// We used inheritance to create this variation of the built-in Frame class so // that it would draw some shapes and respond to mouse clicks and drags. import java.awt.*; public class CustomFrame extends Frame { private int count; private int oldX, oldY; public void paint(Graphics g) { count++; System.out.println("call " + count + " on paint"); g.drawString("Hello World!", 50 + count * 2, 50 + count * 2); g.setColor(Color.YELLOW); g.fillRect(50, 100, 25 + 4 * count, 25 + 4 * count); } public boolean mouseUp(Event e, int x, int y) { System.out.println("(" + x + ", " + y + ")"); Graphics g = getGraphics(); g.setColor(Color.BLUE); g.fillOval(x - 5, y - 5, 10, 10); oldX = x; oldY = y; return true; } public boolean mouseDown(Event e, int x, int y) { System.out.println("(" + x + ", " + y + ")"); Graphics g = getGraphics(); g.setColor(Color.BLUE); g.fillOval(x - 5, y - 5, 10, 10); oldX = x; oldY = y; return true; } public boolean mouseDrag(Event e, int x, int y) { Graphics g = getGraphics(); g.setColor(Color.RED); g.drawLine(oldX, oldY, x, y); oldX = x; oldY = y; return true; } }