• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why is screen flashing when I call repaint()?

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I'm pretty new to applets, but I'm trying to turn my Fractal
explorer program into an applet.
In the original application, I was calling the paintComponent(Graphics g) method, and within this, I was displaying a image, as well as other things, and whenever I had to repaint() the frame many times, it was fine.

But now, I'm using an applet and a paint(Graphics g) method. Again I'm initially displaying an image, and a moving box, but whenever repaint() is called, the screen flashes, the basic code is shown below:


I didn't want to use a JFrame, becuz I wanted the output to go into a rectangle on the HTML screen.
There is an alternative I can think of, using an OverlayLayout, but
I would rather see if there is anyway around this first.
Thanks for any help.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Short answer: use a JApplet instead of an Applet, and use paintComponent(). You'll get double-buffering just like you got in your JFrame.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ahh, but hmmm.
I was invoking this from an HTML file using the tag:


So would that still be ok, to use that?

OK, sorry, I just checked API, and JApplet extends Applet, so it should be ok.
[ November 02, 2005: Message edited by: colin shuker ]
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just tried extending JApplet instead of applet, and using paintComponent
instead of paint, and it didn't work.
Can't see why?
Any ideas?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

it didn't work.



What does that mean?
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh sorry, I should have explained better.
Using JApplet instead of Applet, and paintComponent(Graphics g) instead of paint(Graphics g) now just shows a blank grey screen, except for the panel of 4 buttons at the bottom.

I've created a new small JApplet (see my other post about JApplet), I can't
even get this to draw a line.
I'm probably missing something stupid, but I don't know what.
Any advice is much appreciated, thanks.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've never used JApplets, but there's an introduction over at java.sun.com.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I was looking at it earlier.
I looked at an example, they had an inner class of the class that extends
JApplet, which extended JPanel.
I copied this idea for my applet, but it wouldn't upload when I tried to
use Geocities for my website, because of the $ in the inner class name.

But then I figured out how to write the classes separatly and it worked.
Its taken me the whole day to get this far, but I've finally done it.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic