Repainting rectangles never work for me.

I started a project with the simple JPanel, which apparently is not as simple as it first seemed :(. My goal was to have the rectangle grow one size larger upon clicking it. However, when I click it my MouseListener seems to work, only my repaint() doesn't.

I'm not sure what to do, because this is my first time using repaint and I don't think I'm using it correctly.
One thing I'm not sure about calling the repaint method twice. On the java tutorials, it said the first time ws to fill the current square with the background color, the second to recreate it.

Re: Repainting rectangles never work for me.

I'm sorry, I'm confused. Where in the code above do you increase the size of your rectangle?

Edit: I see that this is your second thread in the forum, and that you never replied to help given to you in your first thread. Please note that if you want to encourage folks to take the time to try to help you, it isn't asking too much of you to take a little time to acknowledge that help, is it? I suggest that you reply to all comments in your previous thread. It's usually best to reply to previous threads before starting new threads.

Re: Repainting rectangles never work for me.

Originally Posted by ManyProblems

I'm pretty sure it's here:

repaint(50,50,20,20);

I was wondering if you were thinking this. No, all this does is redraw a portion of the component, the portion that starts at x = 50, y = 50, with a width and height of 20. It does not change any of the images being drawn. To do that you need to change the numbers that you have here:

The best way to do that is not to use literal numbers in the code above, but rather class int fields, since these can be changed. Then if you want to change the location of the drawn rectangle, you change the values held by the fields and call repaint().