import java.applet.*; import java.awt.*; // Java Drawing Board // Terrence Ma // Modified from Java in a Nutshell public class Board extends Applet { private int last_x = 0, last_y = 0; // Fields to store a point in. // Set color public void init() { this.setBackground(Color.white); this.setForeground(Color.blue); } // Called when the user clicks public boolean mouseDown(Event e, int x, int y) { last_x = x; last_y = y; // Remember the location of the click. return true; } // Called when the mouse moves with the button down public boolean mouseDrag(Event e, int x, int y) { Graphics g = getGraphics(); // Get a Graphics to draw with. g.drawLine(last_x, last_y, x, y); // Draw a line from last point to this. last_x = x; last_y = y; // And update the saved location. return true; } }