// // Written by Nicholas D. Exner, Exner Enterprises C.2000, May 2000 // Class DrawPoly uses code references to other classes such as // ManagePanel.class and Box.class that are the intellectual propertyof // Nicholas Exner. These classes have been included here with the // consent of the author. import java.applet.*; import java.awt.*; import java.util.*; import java.awt.event.*; import java.awt.image.*; public class ToothPick extends Applet { Graphics h; Image offscreenImg; Image sign; Pick p; public void init() { Pick.loadImages((Applet)this,(ImageObserver)this); offscreenImg = createImage(this.size().width,this.size().height); h = offscreenImg.getGraphics(); sign = getImage(getCodeBase(),"sign.gif"); p = new Pick(45,284); p = new Pick(15,286); p.add(new Pick(413,290)); p.add(new Pick(280,146)); p.add(new Pick(151,146)); p.add(new Pick(151,290)); p.add(new Pick(280,290)); p.add(new Pick(15,423,true)); p.add(new Pick(281,425,true)); p.add(new Pick(15,282,true)); p.add(new Pick(151,141,true)); p.add(new Pick(151,282,true)); p.add(new Pick(283,282,true)); setBackground(new Color(200,196,196)); repaint(); } public void paint(Graphics g){ h.setColor(new Color(200,196,196)); h.fillRect(0,0,500,500); h.drawImage(sign,0,0,this); p.show(h); g.drawImage(offscreenImg,0,0,this); } public boolean mouseDown(Event evt, int x, int y) { p.mouseDown(x,y); repaint(); return true; } public boolean mouseUp(Event evt, int x, int y) { p.mouseUp(); repaint(); return true; } public boolean mouseDrag(Event evt, int x, int y) { p.mouseDrag(x,y); repaint(); return true; } public boolean keyDown(Event evt, int key){ if (key == 'r' || key == 'R') if (p.getLast() != null) p.getLast().rotate(); repaint(); return true; } public void update(Graphics g){ paint(g); } } // ENd class //////////// class Pick { int x, y, w, h, pointOnImageX, pointOnImageY; Pick next; Image objImg; boolean select; static Image pickv, pickh; static ImageObserver iobp; static Pick lastPick = null; public Pick(int x, int y){ this.x = x; this.y = y; pointOnImageX = x; pointOnImageY = y; this.next = null; w=8; h=136; select = false; System.out.print("X "+x+" Y1: "+y); objImg = pickv; } public Pick(int x, int y, Pick next){ this(x,y); add(next); } public Pick(int x, int y, boolean bob){ this(x,y); objImg = pickh; } public void add(Pick next){ System.out.println("added"); if (this.next == null) this.next = next; else this.next.add(next); } public static void loadImages(Applet parent,ImageObserver iob){ iobp = iob; MediaTracker tracker = new MediaTracker(parent); pickv = parent.getImage(parent.getCodeBase(),"pickv2.gif"); pickh = parent.getImage(parent.getCodeBase(),"pickh2.gif"); tracker.addImage(pickv,0); tracker.addImage(pickh,1); tracker.checkAll(true); } public void show (Graphics g) { if (objImg != null) g.drawImage(objImg,x,y,iobp); if (next != null) next.show(g); } public void setX(int x) { this.x = x; } public void setY(int y) { this.y = y; } public int getX(){ return x; } public int getY(){ return y; } public Pick getLast(){ return lastPick; } public void rotate(){ if (objImg == pickv){ objImg = pickh; setX(getX()-h/2); setY(getY()+h/2); }else{ objImg = pickv; setX(getX()+h/2); setY(getY()-h/2); } } public void mouseDown(int x1, int y1) { select = false; if (objImg == pickv) if (x1 >= x && x1 <= x+w) if (y1 >= y && y1 <=y+h) select(x1,y1); if (objImg == pickh) if (x1 >= x && x1 <= x+h) if (y1 >= y && y1 <=y+w) select(x1,y1); if (!select && next != null) next.mouseDown(x1,y1); } public void mouseDrag(int x, int y) { if (select) { this.x=(x+pointOnImageX); this.y=(y+pointOnImageY); } else if (next != null) next.mouseDrag(x,y); } public void select(int x1,int y1) { pointOnImageX = x-x1; pointOnImageY = y-y1; select = true; lastPick = this; } public void mouseUp() { select = false; if (next != null) next.mouseUp(); } } // End class //////////