问题描述
这是我的代码,现在的问题是只能用其中的四个点画曲线,如果想把这些点都加进去,或者说给定随机个数的点,应该怎样修改,来画曲线?求大神帮助,谢谢。importjava.awt.Color;importjava.awt.Frame;importjava.awt.Graphics;importjava.awt.Graphics2D;importjava.awt.event.WindowAdapter;importjava.awt.event.WindowEvent;importjava.awt.geom.GeneralPath;publicclassBezLabextendsFrame{publicstaticint[]x={75,150,300,375,450,270};publicstaticint[]y={250,100,350,250,300,500};publicstaticint[]xs=newint[100];publicstaticint[]ys=newint[100];publicstaticvoidmain(String[]args){for(intk=0;k<4;k++){xs[k]=x[k];ys[k]=y[k];}(newBezLab()).setVisible(true);}privateintdragIndex=NOT_DRAGGING;privatefinalstaticintNEIGHBORHOOD=15;privatefinalstaticintNOT_DRAGGING=-1;BezLab(){setSize(500,450);addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});}publicvoidpaint(Graphicsg){for(inti=0;i<4;i++){if(i==0||i==3)g.setColor(Color.blue);elseg.setColor(Color.cyan);g.fillOval(xs[i]-6,ys[i]-6,12,12);}Graphics2Dg2d=(Graphics2D)g;g2d.setColor(Color.black);GeneralPathpath=newGeneralPath();path.moveTo(xs[0],ys[0]);path.curveTo(xs[1],ys[1],xs[2],ys[2],xs[3],ys[3]);g2d.draw(path);}}菜鸟,只有这么多分,还请包涵。。