import java.awt.*; public class SplineApplet extends BufferedApplet { private int pointToMove = -1; private boolean drawCircles = true, drawGuideOutline = true, drawText = true, closedCurve = true, smootheCurve = true, drawCurve = true; PolyBezier pb = new PolyBezier(2, closedCurve, smootheCurve, 200); public void render(Graphics g) { if (damage) { g.setColor(Color.white); g.fillRect(0, 0, bounds().width, bounds().height); g.setColor(Color.black); if (drawGuideOutline) pb.drawGuidelines(g); if (drawCircles) pb.drawPoints(g); if (drawText) pb.writeCoordinates(g); if (drawCurve) pb.drawCurve(g); } } public boolean keyDown(Event e, int key) { switch (key) { case '1': pb = new PolyBezier(1, closedCurve, smootheCurve, 200); break; case '2': pb = new PolyBezier(2, closedCurve, smootheCurve, 200); break; case '3': pb = new PolyBezier(3, closedCurve, smootheCurve, 200); break; case '4': pb = new PolyBezier(4, closedCurve, smootheCurve, 200); break; case '5': pb = new PolyBezier(5, closedCurve, smootheCurve, 200); break; case '6': pb = new PolyBezier(6, closedCurve, smootheCurve, 200); break; case '7': pb = new PolyBezier(7, closedCurve, smootheCurve, 200); break; case '8': pb = new PolyBezier(8, closedCurve, smootheCurve, 200); break; case '9': pb = new PolyBezier(9, closedCurve, smootheCurve, 200); break; case '0': pb = new PolyBezier(10, closedCurve, smootheCurve, 200); break; case 'h': case 'H': pb.smootheEdges(); break; case 's': case 'S': drawCurve = (drawCurve ? false : true); break; case 'm': case 'M': smootheCurve = (smootheCurve ? false : true); pb.setSmoothe(smootheCurve); break; case 'o': case 'O': closedCurve = (closedCurve ? false : true); pb.setClosed(closedCurve); break; case 'r': case 'R': pb.initCurves(); break; case 'c': case 'C': drawCircles = (drawCircles ? false : true); break; case 'g': case 'G': drawGuideOutline = (drawGuideOutline ? false : true); break; case 't': case 'T': drawText = (drawText ? false : true); break; case 'i': case 'I': drawCircles = (drawCircles ? false : true); drawGuideOutline = (drawGuideOutline ? false : true); drawText = (drawText ? false : true); break; case 'a': case 'A': boolean set; if (drawCircles) set = false; else set = true; drawCircles = set; drawGuideOutline = set; drawText = set; break; } damage = true; return true; } public boolean mouseDrag(Event e, int x, int y) { if (pointToMove != -1) { pb.setPoint(pointToMove, x, y); damage = true; } return true; } public boolean mouseDown(Event e, int x, int y) { int[] point; for (int i = 0; i < (4 * pb.getNumCurves()); i++) { point = pb.getPoint(i); if ( point[0] - 5 < x && x < point[0] + 5 && point[1] - 5 < y && y < point[1] + 5) pointToMove = i; } System.out.println("Point grabbed: " + pointToMove); damage = true; return true; } public boolean mouseUp(Event e, int x, int y) { pointToMove = -1; damage = true; return true; } }