File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why is screen flashing when I call repaint()?

 
colin shuker
Ranch Hand
Posts: 750
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it didn't work.


What does that mean?
 
colin shuker
Ranch Hand
Posts: 750
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic