/** * RepaintApplet.java * Shows a bad way to do drawing.The drawing code is outside the paint() method * so that the draws are not restored after iconification or other windows covering * and uncovering the window. * The programmer' drawing code does not coordinate with painting by the AWT GUI * thread. * See other programs in the RepaintAppletX.java sequence for improvements * USAGE: Click the screen near the upper left corner of the textarea * of the browser. Then iconify and de-iconify the browrser or * go to another page. */ import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class RepaintApplet extends Applet { public void init() { addMouseListener(new HandleMouse()); } class HandleMouse extends MouseAdapter { public void mouseClicked(MouseEvent e) { Graphics g = getGraphics(); g.setColor(Color.yellow); g.fillRect(0,0,getSize().width, getSize().height); g.setColor(Color.red); g.fillOval(e.getX()-10, e.getY()-10, 20, 20); } } }