home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-03-08 | 1.1 KB | 53 lines |
- import java.awt.*;
- import java.applet.*;
-
- public class MouseApplet2 extends Applet
- {
- Point startPoint;
- Point points[];
- int numPoints;
- boolean drawing;
-
- public void init()
- {
- startPoint = new Point(0, 0);
- points = new Point[1000];
- numPoints = 0;
- drawing = false;
- resize(400, 300);
- }
-
- public void paint(Graphics g)
- {
- int oldX = startPoint.x;
- int oldY = startPoint.y;
-
- for (int x=0; x<numPoints; ++x)
- {
- g.drawLine(oldX, oldY, points[x].x, points[x].y);
- oldX = points[x].x;
- oldY = points[x].y;
- }
- }
-
- public boolean mouseDown(Event evt, int x, int y)
- {
- drawing = true;
- startPoint.x = x;
- startPoint.y = y;
- return true;
- }
-
- public boolean mouseMove(Event evt, int x, int y)
- {
- if ((drawing) && (numPoints < 1000))
- {
- points[numPoints] = new Point(x, y);
- ++numPoints;
- repaint();
- }
-
- return true;
- }
- }
-