repaint() in Java

Status
Not open for further replies.

s-01

Ars Tribunus Militum
2,734
Subscriptor
I'm working on a program for my Java class. In this program I have the main class dopewars1 and some sub-classes: Cities, cops, copFight, and player.

In dopewars1 I have a canvas everytime something changes in the subclasses I need to repaint the Canvas. I call the repaint() method
and it does nothing. The only way to get the Canvas to repaint is to resize the window or minimize/maximize it, etc.

Since dopewars1 implements WindowListener I've tried to call repaint() from the windowClosed and the windowClosing methods but to no avail. I've also tried calling repaint() from the subclasses.

The program is a little long so below is a link to all the code if you're interested.

http://www.sevencorp.net/dopewars.zip

Thanks for any help.
 

gumbo

Ars Tribunus Angusticlavius
6,107
It is generally better to call repaint() on the component that needs repainting. A general repaint to the entire app UI may take longer to execute, update later, or, as in your case, not work at all. If you did not extend any graphics classes on dopewars1 (I can't look at the code right now), it may compile, but shouldn't work. repaint() has no object to repaint, and so will fail.

gubmo
 
Status
Not open for further replies.