• Post Reply Bookmark Topic Watch Topic
  • New Topic

JApplet repaint

 
mailssk
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to scroll a line of text in JApplet. and it does not clear the screen after every display of the line. It keeps overwriting. Can anyone help.
Regds.
Shiva
 
Grant Crofton
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never programmed a graphical Applet (or a JApplet at all), so I'm not sure how they work.
There are a couple of generic thing you could try:
you could paint over the old text with the same text in black (or whatever the background colour is - won't work if it's a picture) before drawing the new line of text
Double buffer the graphics, which involves drawing your text (or whatever) to an off-screen image, then copying that image to the screen (where currently you draw straight onto the screen).
You do that like this:
public void paint( Graphics g )
{
Image im = createImage( WIDTH, HEIGHT );
Graphics g2 = im.getGraphics();
g2.drawString( "Hello", XPos, YPos );
g.drawImage( im, 0, 0, null );
}
where WIDTH, HEIGHT, XPos and YPos are ints.
I'm sure my teacher told me that Swing stuff automatically uses double buffering, but I haven't used it, so I'm not sure.

Hope that works.
 
Grant Crofton
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, missed a bit of writing - I didn't mean you have to double buffer the graphics if you draw over the old text.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!