home *** CD-ROM | disk | FTP | other *** search
/ Learn Java Now / Learn_Java_Now_Microsoft_1996.iso / JavaNow / Code / Chap13 / ConnectTheDots / ConnectTheDots.class (.txt) next >
Encoding:
Java Class File  |  1996-07-29  |  2.2 KB  |  68 lines

  1. import java.applet.Applet;
  2. import java.awt.Component;
  3. import java.awt.Dimension;
  4. import java.awt.Event;
  5. import java.awt.Graphics;
  6.  
  7. public class ConnectTheDots extends Applet {
  8.    static final int m_nMAXLOCS = 100;
  9.    Dimension[] m_dimLocs = new Dimension[100];
  10.    int m_nNumMouseClicks = 0;
  11.    Dimension m_dimCursorLoc = new Dimension(0, 0);
  12.  
  13.    public void start() {
  14.    }
  15.  
  16.    public void stop() {
  17.    }
  18.  
  19.    public boolean mouseMove(Event evt, int x, int y) {
  20.       this.m_dimCursorLoc = new Dimension(x, y);
  21.       ((Component)this).repaint();
  22.       return true;
  23.    }
  24.  
  25.    public boolean mouseDown(Event evt, int x, int y) {
  26.       if (this.m_nNumMouseClicks < 100) {
  27.          this.m_dimLocs[this.m_nNumMouseClicks] = new Dimension(x, y);
  28.          ++this.m_nNumMouseClicks;
  29.          ((Component)this).repaint();
  30.       }
  31.  
  32.       return true;
  33.    }
  34.  
  35.    public boolean mouseDrag(Event evt, int x, int y) {
  36.       return true;
  37.    }
  38.  
  39.    public String getAppletInfo() {
  40.       return "Name: ConnectTheDots\r\n" + "Author: Stephen R. Davis\r\n" + "Created for Learn Java Now (c)";
  41.    }
  42.  
  43.    public boolean mouseUp(Event evt, int x, int y) {
  44.       return true;
  45.    }
  46.  
  47.    public void destroy() {
  48.    }
  49.  
  50.    public void init() {
  51.       ((Applet)this).resize(400, 400);
  52.    }
  53.  
  54.    public void paint(Graphics g) {
  55.       int nX = this.m_dimCursorLoc.width;
  56.       int nY = this.m_dimCursorLoc.height;
  57.       g.drawLine(nX - 2, nY, nX + 2, nY);
  58.       g.drawLine(nX, nY - 2, nX, nY + 2);
  59.  
  60.       for(int i = 0; i < this.m_nNumMouseClicks - 1; ++i) {
  61.          for(int j = i + 1; j < this.m_nNumMouseClicks; ++j) {
  62.             g.drawLine(this.m_dimLocs[i].width, this.m_dimLocs[i].height, this.m_dimLocs[j].width, this.m_dimLocs[j].height);
  63.          }
  64.       }
  65.  
  66.    }
  67. }
  68.