June 2005
Beginner to intermediate
336 pages
6h 29m
English
Besides the swim method, the Fish class also has a drawFishImage method, which will draw the fish. Note that the last line in the run method, after each fish has been moved to a new position by the swim method, calls the window's repaint method to redraw the aquarium:
while (runOK) {
for (int loopIndex = 0; loopIndex < numberFish; loopIndex++){
fish = (Fish)fishes.elementAt(loopIndex);
fish.swim();
}
try {
Thread.sleep(sleepTime);
}
catch (Exception exp) {
System.out.println(exp.getMessage());
}
repaint();
}
The repaint method calls the update method, which is where flickering usually happens, because by default the update method first redraws the entire window using the background window color. To avoid that flickering, ...
Read now
Unlock full access