0

So when I alt-tab between the applet and something else, may it be another window or just the desktop, the applet ends up looking like this when I come back to it: enter image description here

This is the Embed gadget I use on the google site I host my applet on. Normally it would just be my applet, but it shows the stuff that I had recently alt-tabbed away from.

It also does this in Eclipse's applet viewer. Not just this applet, but every applet I've made (which is why I don't think it has anything to do with the code of this applet in particular).

Is this a problem related to the way I write my paint() method, or is it something else?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
liboan1997
  • 53
  • 4
  • Have you cleared the graphics? Normally the screen doesn't clear what it's been printing unless you explicitly tell it to. ``clearRect(0, 0, width, height)`` usually does it. – Jens Egholm Nov 06 '12 at 14:24
  • Have you tried to add your own [`FocusListener`](http://docs.oracle.com/javase/6/docs/api/java/awt/event/FocusListener.html) that overrides `focusGained` and `focusLost` to do a repaint, to the applet with [`addFocusListener`](http://docs.oracle.com/javase/6/docs/api/java/awt/Component.html#addFocusListener%28java.awt.event.FocusListener%29)? – halex Nov 06 '12 at 14:34
  • 1
    Are you calling `super.paint(g);` in your `paint` method? – Reimeus Nov 06 '12 at 23:27
  • I'm not doing any of them, though I will definitely try the first one, the second one seems a little complicated, and though I _did_ call super.paint(g), it worked, and when I alt-tabbed the triangle disappeared. – liboan1997 Nov 07 '12 at 03:04
  • 2
    The advice offered by @Reimeus is what I would look into more. The fact the triangle disappears suggests that you are unaware it needs to be drawn each time the paint method is called (and it is called repeatedly, whenever the JRE determines it is necessary). – Andrew Thompson Nov 07 '12 at 05:39

0 Answers0