Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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!