home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-06-17 | 2.6 KB | 112 lines |
- //**************************************************************
- // ConnectTheDots.java: Applet
- //
- //**************************************************************
- import java.applet.*;
- import java.awt.*;
-
- public class ConnectTheDots extends Applet
- {
- // user defined data
- // the following is a recording of all
- // previous clicked locations
- static final int m_nMAXLOCS = 100;
- Dimension m_dimLocs[];
- int m_nNumMouseClicks;
-
- // the current cursor location
- Dimension m_dimCursorLoc;
-
- public ConnectTheDots()
- {
- // initialize the object data members
- m_dimLocs = new Dimension[m_nMAXLOCS];
- m_nNumMouseClicks = 0;
- m_dimCursorLoc = new Dimension(0, 0);
- }
-
- public String getAppletInfo()
- {
- return "Name: ConnectTheDots\r\n" +
- "Author: Stephen R. Davis\r\n" +
- "Created for Learn Java Now (c)";
- }
-
-
- public void init()
- {
- resize(400, 400);
-
- }
-
- public void destroy()
- {
- }
-
- public void paint(Graphics g)
- {
- // put a cross where the cursor is located
- int nX = m_dimCursorLoc.width;
- int nY = m_dimCursorLoc.height;
- g.drawLine(nX - 2, nY, nX + 2, nY);
- g.drawLine( nX, nY - 2, nX, nY + 2);
-
- // now draw a line from each clicked location
- // to every other clicked location
- for (int i = 0; i < m_nNumMouseClicks - 1; i++)
- {
- for (int j = i + 1; j < m_nNumMouseClicks; j++)
- {
- g.drawLine(m_dimLocs[i].width,
- m_dimLocs[i].height,
- m_dimLocs[j].width,
- m_dimLocs[j].height);
- }
- }
- }
-
- public void start()
- {
- }
-
- public void stop()
- {
- }
-
-
- public boolean mouseDown(Event evt, int x, int y)
- {
- // record the click location (if there's enough room)
- if (m_nNumMouseClicks < m_nMAXLOCS)
- {
- m_dimLocs[m_nNumMouseClicks] = new Dimension(x, y);
- m_nNumMouseClicks++;
-
- // now force the window to repaint
- repaint();
- }
- return true;
- }
-
- public boolean mouseUp(Event evt, int x, int y)
- {
- // ignore the mouseUp event
- return true;
- }
-
- public boolean mouseDrag(Event evt, int x, int y)
- {
- // ignore the mouseDrag event
- return true;
- }
-
- public boolean mouseMove(Event evt, int x, int y)
- {
- // record the mouse location and repaint it
- m_dimCursorLoc = new Dimension(x, y);
- repaint();
- return true;
- }
-
- }
-