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;
-
- public class ConnectTheDots extends Applet {
- static final int m_nMAXLOCS = 100;
- Dimension[] m_dimLocs = new Dimension[100];
- int m_nNumMouseClicks = 0;
- 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 (this.m_nNumMouseClicks < 100) {
- this.m_dimLocs[this.m_nNumMouseClicks] = new Dimension(x, y);
- ++this.m_nNumMouseClicks;
- ((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);
-
- for(int i = 0; i < this.m_nNumMouseClicks - 1; ++i) {
- for(int j = i + 1; j < this.m_nNumMouseClicks; ++j) {
- g.drawLine(this.m_dimLocs[i].width, this.m_dimLocs[i].height, this.m_dimLocs[j].width, this.m_dimLocs[j].height);
- }
- }
-
- }
- }
-