home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Java / FreeJava10 / _SETUP.1 / DrawCanvas.java < prev    next >
Encoding:
Java Source  |  1998-10-05  |  767 b   |  36 lines

  1. import java.awt.*;
  2. import java.awt.event.*;
  3.  
  4. public class DrawCanvas extends MouseableCanvas
  5. {
  6.     int mx[];
  7.     int my[];
  8.     int counter = 0;
  9.     static final int ARRAYSIZE = 100;
  10.     
  11.     public DrawCanvas()
  12.     {
  13.         mx = new int[ARRAYSIZE ];
  14.         my = new int[ARRAYSIZE ];
  15.     }
  16.     
  17.     public void mousePressed(MouseEvent e)
  18.     {
  19.         mx[counter] = e.getX();
  20.         my[counter] = e.getY();
  21.         System.out.println("x: " + mx[counter] + "  y: " + my[counter]);
  22.         Graphics g = this.getGraphics();
  23.         if(counter > 0)
  24.             g.drawLine(mx[counter-1], my[counter-1], mx[counter], my[counter]);
  25.         counter++;
  26.         if(counter > ARRAYSIZE-1) counter = 0;
  27.     }
  28.     
  29.     public void paint(Graphics g)
  30.     {
  31.         for(int i = 0; i < counter-1; i++)
  32.         {
  33.             g.drawLine(mx[i], my[i], mx[i+1], my[i+1]);
  34.         }
  35.     }
  36. }