// draw3D2.java opens three view windows X-Y X-Z Z-Y // opens 3D window and Menu window // select color, shape, placement // no painters algorithm, yet import java.*; import java.awt.*; import java.awt.event.*; import java.util.*; // get LinkedList public class draw3D2 { final int width = 300; // window final int height = 300; final int Mwidth = 200; // menu final int mh = 20; int xm, ym, bm; // mouse position (inverted y) int x0, y0, z0, x1, y1, z1; // "rubber" coordinates int x2, y2, z2, x3, y3, z3; // "extra points" boolean topView = true; boolean frontView = true; boolean rightView = true; boolean gridOn = true; int grid = 50; // grid spacing int bo = 300; // for color Menu int ba = 45; // for color Menu Color drawColor = new Color(255, 0, 0); // Color of object being drawn int objSelect = 0; // can be sequences // -1 object container, possible internal drawList // 0=cube face 1, 1x=cube third dimension // 2=sphere center and edge, 3x=sphere center third dimension LinkedList drawList = new LinkedList(); // list of objects, initially empty objCube objC; // temp cube object objSphere objS; // temp sphere object int instanceCount = 0; // give each object a unique instance int xp; // last mouse location during drag int yp; boolean trackingXY = false; // tracking XY mouse motion boolean trackingXZ = false; // tracking XZ mouse motion boolean trackingZY = false; // tracking ZY mouse motion Frame fXY, fXZ, fZY, f3D, fMenu; Graphics gXY, gXZ, gZY, g3D, gMenu; draw3D2() { System.out.println("draw3D2 starting"); // each thread opens its own window new MyThread("X-Y", Mwidth, height).start(); new MyThread("X-Z", Mwidth, 0).start(); new MyThread("Z-Y", width+Mwidth, height).start(); new MyThread("3D" , width+Mwidth, 0).start(); new MyThread("Menu", 0, 0).start(); System.out.println("draw3D2 constructor ending"); } // end draw3D2 constructor class MyThread extends Thread { String id; Graphics g; Frame f; MyThread(String who, int xLoc, int yLoc) { id = who; // initiate a window for each thread f = new Frame(); f.setTitle("draw3D2 "+who); f.setLocation(xLoc, yLoc); if(id=="Menu") f.setSize(Mwidth, 2*height); else f.setSize(width, height); f.setBackground(Color.white); f.setForeground(Color.black); f.setVisible(true); g = f.getGraphics(); // every window has its Frame, Graphics f.addWindowListener(new WindowAdapter() // and Listeners { public void windowClosing(WindowEvent e) { System.exit(0); } }); f.addMouseListener (new mousePressHandler()); f.addMouseListener (new mouseReleaseHandler()); f.addMouseMotionListener (new mouseMotionHandler()); } // end MyThread constructor public void run() { try { System.out.println(id+" running"); if (id=="X-Y") {fXY=f; gXY=g;} else if(id=="X-Z") {fXZ=f; gXZ=g;} else if(id=="Z-Y") {fZY=f; gZY=g;} else if(id=="3D") {f3D=f; g3D=g;} else if(id=="Menu"){fMenu=f; gMenu=g; paint(g);} sleep(1); } catch(InterruptedException e) { } System.out.println("run exiting"); } // end MyThread run } // end class MyThread public void paint(Graphics g) { // call methods to do actual drawing // System.out.println("paint running"); drawXY(fXY, gXY); drawXZ(fXZ, gXZ); drawZY(fZY, gZY); draw3D(f3D, g3D); drawMenu(fMenu, gMenu); } // end paint public void drawXY(Frame f, Graphics g) { objList objL; // System.out.println("in drawXY"); g.clearRect(0, 0, width, height); g.setColor(Color.black); if(gridOn) for(int i=grid; ix && xmy && ym