Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization 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
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

New to programming and java - very simple asteroids program which flickers (buffering issue?)

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys

Im new to programming and java and these forums so please bare with me, below is the code i am currently working on (following a textbook) but ive checked over the code and as far as i can see everything is correct but when i run the applet i just get a black and white flashing screen. I am assuming that it is something to do with the buffer or painting but i just cant figure out what. If anyone could point me in the right direction that would be great (the applet is a VERY simple version of asteroids which i will improve upon but need to get this portion working first)

If you have any ideas awesome shove me in the right direction if not thanks for looking anyway

Posts: 3776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Ben,

the idea is to let the game thread do all the updating: the updating of the objects AND
the updating of your BufferedImage. So it is the run() method where all the updating should
take place; not in the update(Graphics g) method.

And when that is done, you issue a repaint(), which, IIRC, issues first
the update(g) method, and then the paint(g) method.

So, do all the updating of both the objects and the BufferedImage in the run() method,
then issue repaint(), and all that you have to do then is:

And you could try to experiment with Thread.sleep(..); Java is fast enough to let you do more than 50
redraws per second. I remember from the old CRTs that a refresh rate of 50 caused a lot
of flickering. Well, that should be far less with the current LCD's of course.

I'm gonna teach you a lesson! Start by looking at this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!