• Post Reply Bookmark Topic Watch Topic
  • New Topic

Flickering in JApplet  RSS feed

 
Sergei Voropay
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on an applet derived from JApplet class. When running the applet in browser and scrolling the page in any direction, the applet flickers. Is there a way of getting rid of this annoying behavior?
 
manav kher
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well that might be because the paint method is being called every time and basically it goes like this
paint() is called
update() is called by default it clears the screen
and then paint() is called again to redraw the screen
what u can do is override update() so that the screen is not cleared and let paint handle everything
-manav
 
ming fan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another way to handle that is to have your own local buffer image and draw on that first, then draw the image onto the graphics object passed in by the system.
code example:
/* These are your buffers */
Image buffer;
Graphics bufferGraphics;
public void paint(Graphics g)
{
Dimension d = getSize();
if (buffer == null)
{
buffer = createImage(d.width, d.height);
bufferGraphics = buffer.getGraphics();
}
bufferGraphics.drawLine(0, 0, 100, 100);
g.drawImage(buffer, 0, 0, this);
}
You can also use the bufferGraphics in other methods according to your needs.

Originally posted by Sergei Voropay:
I'm working on an applet derived from JApplet class. When running the applet in browser and scrolling the page in any direction, the applet flickers. Is there a way of getting rid of this annoying behavior?

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!