• 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

JApplet repaint  RSS feed

 
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
 
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!