需要代码,谢谢!

解决方案 »

  1.   

    这是我写的一个画三次Beizer曲线的代码
    有4个控制点
    你只要换成2次Beizer曲线就可以了
    2次Beizer曲线要3个控制点public class JBeizer extends JOpenShape {
        
        CubicCurve2D.Double c2d = new CubicCurve2D.Double();
        
        /** Creates a new instance of JBeizer */
        public JBeizer(int x, int y) {
            setStartPoint(x, y);
            c2d.ctrlx1 = c2d.ctrlx2 = c2d.x2 = x;
            c2d.ctrly1 = c2d.ctrly2 = c2d.y2 = y;
            this.locationX = x; this.locationY = y;     //设置位置
        }
        
        public void setStartPoint(int x, int y) {
            c2d.x1 = x;
            c2d.y1 = y;
        }
        
        public void setNewPoint(int x, int y, int i) {
            switch (i) {
                case 1:
                    c2d.x2 = c2d.ctrlx1 = c2d.ctrlx2 = x;
                    c2d.y2 = c2d.ctrly1 = c2d.ctrly2 = y;
                    break;
                case 2:
                    c2d.ctrlx1 = c2d.ctrlx2 = x;
                    c2d.ctrly1 = c2d.ctrly2 = y;
                    break;
                case 3:
                    c2d.ctrlx2 = x;
                    c2d.ctrly2 = y;
                    break;
            }
        }
            public void drawShape(Graphics2D g2d) {
            g2d.setColor(this.shapeColor);
            g2d.setStroke(this.sStr);
            g2d.draw(c2d);
        }
    }
      

  2.   

    这个要配合mouseClicked事件
    以下代码是我里面的一部分if (JShape.typeId == JShape.TYPE_BEIZER) {
                        currentShape.setNewPoint(evt.getX(), evt.getY(), clickCount);
                        clickCount++;
                        if (clickCount > 3) {
                            isFirstClick = true;
                            currentShape.setShapeColor(fatherFrame.penColor);
                            currentShape.setStrokeNum(fatherFrame.lStroke);
                            currentShape.setLineStyle(fatherFrame.lStyle);
                            recover();
                        } 
                    }画三次Beizer曲线的二次Beizer曲线的类是 QuadCurve2D
    具体用法你就看api吧!
    祝你成功!