home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Event;
- import java.awt.Graphics;
- import java.util.Vector;
-
- public class ConnectTheDots extends Applet {
- Vector m_vLocs = new Vector();
- Dimension m_dimCursorLoc = new Dimension(0, 0);
-
- public void start() {
- }
-
- public void stop() {
- }
-
- public boolean mouseMove(Event evt, int x, int y) {
- this.m_dimCursorLoc = new Dimension(x, y);
- ((Component)this).repaint();
- return true;
- }
-
- public boolean mouseDown(Event evt, int x, int y) {
- if (evt.clickCount > 1) {
- this.m_vLocs.removeAllElements();
- } else {
- this.m_vLocs.addElement(new Dimension(x, y));
- }
-
- ((Component)this).repaint();
- return true;
- }
-
- public boolean mouseDrag(Event evt, int x, int y) {
- return true;
- }
-
- public String getAppletInfo() {
- return "Name: ConnectTheDots\r\n" + "Author: Stephen R. Davis\r\n" + "Created for Learn Java Now (c)";
- }
-
- public boolean mouseUp(Event evt, int x, int y) {
- return true;
- }
-
- public void destroy() {
- }
-
- public void init() {
- ((Applet)this).resize(400, 400);
- }
-
- public void paint(Graphics g) {
- int nX = this.m_dimCursorLoc.width;
- int nY = this.m_dimCursorLoc.height;
- g.drawLine(nX - 2, nY, nX + 2, nY);
- g.drawLine(nX, nY - 2, nX, nY + 2);
- int nSize = this.m_vLocs.size();
-
- for(int i = 0; i < nSize - 1; ++i) {
- Dimension dimFrom = (Dimension)this.m_vLocs.elementAt(i);
-
- for(int j = i + 1; j < nSize; ++j) {
- Dimension dimTo = (Dimension)this.m_vLocs.elementAt(j);
- g.drawLine(dimFrom.width, dimFrom.height, dimTo.width, dimTo.height);
- }
- }
-
- }
- }
-