Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating and moving dots\icons on GUI  RSS feed

 
Kari Nordmann
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!