Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Carey Brown
  • Frits Walraven

Creating and moving dots\icons on GUI

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 ]
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.
pie. tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
    Bookmark Topic Watch Topic
  • New Topic