• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

repaint() not erasing/redrawing strings?

 
Gunslinger
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all. Here's my dilemma: I'm trying to create an applet that asks for simple multiplication answers, and draws a string giving feedback after the question is answered ("Very good!" or "No, try again."). The problem is that the book says to draw everything from paint(), and gives the impression that repaint() should magically refresh everything on the applet, which it does not. How can I make the strings I drew in paint() go away and give way to new strings based on user answer (whether correct or not), instead of piling up on top of each other, because they don't refresh? Thanks for your time!
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

Please don't post the same question to more than one forum. See here for an explanation of why I just deleted the other copies of this thread.

JApplet works differently from the old-fashioned Applet class, and in particular, it's not really intended to have its paint() method overridden. If you need to do graphics, you're supposed to do the graphics on a JPanel, and add the JPanel to the JApplet's root pane.

My recommendation is just to use java.applet.Applet instead of javax.swing.JApplet to write this kind of code. If you really want to use JApplet, then subclass JPanel, do the graphics in the paintComponent() method of the JPanel (calling super.paintComponent() first) and then add this JPanel to your JApplet.
 
a wee bit from the empire
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic