I'm making a little aquarium game, where I want the user to be able to see the fish when it appears. So there will be the aquarium itself, then 1 fish, 2 fish and later there can be lots of them, moving around in the water.
My problem is how to create and move the fish around with a timer. By looking at examples from web I've put together a small program that creates a small dot and moves it around every tick, but I don't see why I only get 1 dot when I want several.
I notice that when I run the program, "TegnDotter B" and "TegnDotter D" only happens once every tick, even though "TegnDotter C" happens for evry dot every tick. So why won't repaint work for all the dots? [ June 13, 2008: Message edited by: Kari Nordmann ]
Post by:Craig Wood
, Ranch Hand
So why won't repaint work for all the dots? The first problem is with adding components to the center section of the contentPane:
Each time you add a component to a section of a container which already has a child component in that section, the existing child component is removed and the new component is added. So only the last component will remain after the for loop executes. See the second sentence in the first paragraph of the comments section in the BorderLayout api. Here's another way you could put this together.