Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8647939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:11:47+00:00 2026-06-12T13:11:47+00:00

Possible Duplicate: Drawing multiple pixels/rectangles In my code i wrote a method that creates

  • 0

Possible Duplicate:
Drawing multiple pixels/rectangles

In my code i wrote a method that creates a rectangle at mouseX, mouseY. but all it does is update the position of that rectangle so it follows the mouse, i want it to create a new one at the mouse every time the method runs, can someone please help?

this is my method

public void drawParticle(float x, float y){
    g.drawRect(x, y, 4, 4);
}

The main class Control call the drawParticle method;

import java.awt.Point;
import java.awt.geom.Point2D;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

public class Control extends BasicGameState {
    public static final int ID = 1;

    public Methods m = new Methods();
    public Graphics g = new Graphics();

    int mouseX;
    int mouseY;


    public void init(GameContainer container, StateBasedGame game) throws SlickException{
    }

    public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
        m.drawParticle(mouseX, mouseY);
    }

    public void update(GameContainer container, StateBasedGame game, int delta) {
    }

    public void mousePressed(int button, int x, int y) {
        mouseX = x;
        mouseY = y;
    }

    public int getID() {
        return ID;
    }

}

Thanks – Shamus

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:11:48+00:00Added an answer on June 12, 2026 at 1:11 pm

    One way to do this is to create a List as a member variable and add a new Rectangle each time the user clicks the mouse. Then in your render() method, iterate through the List of Rectangles and paint each one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Use a System.Drawing.Printing.PrintDocument to generate a PDF in memory I wrote a
Possible Duplicate: Is there a way of drawing a caption box in matplotlib Is
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: thread with multiple parameters How does one thread a sub with two
Possible Duplicate: How can I combine multiple rows into a comma-delimited list in Oracle?
Possible Duplicate: Does std::list::remove method call destructor of each removed element? I have a
Possible Duplicate: Resizing an Image without losing any quality The code I always use
Possible Duplicate: How to successfully rewrite old mysql-php code with deprecated mysql_* functions? I
Possible Duplicate: How to get Color from Hex color code using .NET? I want
Possible Duplicate: Combine Multiple child rows into one row MYSQL I have following table,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.