Draw 3D Lines:



This applet shows the capabilities of "DRAW" class embedded in Java platform that enable you to draw different kinds of maps. The mouse event of click, drag and move was traced to draw the line.

Web Configuration:

<applet code="Line3D.class" codebase="applet" width=250 height=250>
</applet>

Source Code:

import java.awt.*;

public class Line3D extends java.applet.Applet {
    int currx;
    int curry;
    final int MAXPOINT = 1000;
    int pointx[]= new int[MAXPOINT];
    int pointy[]= new int[MAXPOINT];
    int currline;

    /** Initializes the applet Line3D */
    public void init () {
    currx = curry = currline = 0;
    setBackground(Color.red);
    for(int i = 0; i < MAXPOINT; i++) 
    pointx[i] = pointy[i] = 0; //sets all to 0
    }

    public void paint(Graphics g) {
        for(int i=0; i<currline; i++) {
            if(pointx[i] == 0|| pointy[i] == 0)
                break;
            }else
               {g.drawLine(pointx[i], pointy[i], currx,curry);
            }
            g.drawString("Lines: "+currline, 1, getSize().height-5);
         }
     }

     public boolean mouseMove(Event e, int x, int y){
        currx = x;
        curry = y;
        repaint();
        return true;
     }

     public boolean mouseDown(Event e, int x, int y){
        pointx[currline]=x;
        pointy[currline]=y;
        currline++;
        return true;
     }

     public boolean mouseDrag(Event e, int x, int y){
     pointx[currline]=x;
     pointy[currline]=y;
     currx=x; 
     curry=y;
     currline++;
     repaint();
     return true;
     }
}

 

 

Copyright©2002, All Right Reserved

Department of Geography, San Diego State University