一个动态显示问题,GUI高手请进!(有源码)
下面的程序希望通过一个算法来动态画出一个简单图形
可是在开始按钮里加循环去不能够实现,请高手指教!!
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.io.*;
import javax.swing.*;
import java.util.Vector;
import java.util.Date;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.lang.*;
//定义myQuadCurve类,扩展Frame类,加入myQuadCurvePanel
public class ShowArithmeticTest1 extends JFrame
{
public ShowArithmeticTest1(){
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
JPanel showPanel = createShowPanel();
this.setSize(500,400);
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().setBackground(Color.black);
this.getContentPane().add(showPanel,BorderLayout.CENTER);
this.show();
}
public JPanel createShowPanel()//**实时动画显示面板
{
JPanel showPanel = new JPanel();
myQuadCurvePaneltest p = new myQuadCurvePaneltest();
p.setSize(400,300);
p.setBackground(Color.black);
showPanel.setLayout(new BorderLayout());
showPanel.setBorder(BorderFactory.createTitledBorder("实时动画显示"));
showPanel.add(p,BorderLayout.CENTER);
return showPanel;
}
//定义mian()方法,显示窗体
public static void main(String[] args){
ShowArithmeticTest1 f = new ShowArithmeticTest1();
}
};
//定义myQuadCurvePanel类,扩展JPanel类!
class myQuadCurvePaneltest extends JPanel implements ActionListener
{
Vector queue = new Vector();
BorderLayout borderLayout = new BorderLayout();
Panel pdown = new Panel();
Checkbox check1,check2;
JButton btn;
JLabel p1,p2;
JLabel L1,L2,L3;
Point[] x = new Point[2];
int i,j = 0,k,flag = 0;
String ts1,ts2,ts3;
////////////////////////////////////////////////////////////
public double x1,y1,x2,y2;
public int countT,count;
public double newx1,newy1,newx2,newy2;
public double t1,v1,w1,t2,v2,w2;
public double d1,d2,k1,k2,ko,kf,T;
public double pi = Math.PI;
public boolean s = true;//对应s=0
public double l12d,f12d,l12,f12,f,e1,e2,e3;
double sign0,rd,ld,fai,r;
public void init(){
T = 1.5;
countT = 50;
count = 1;
l12d =3;
f12d = pi*150/100;
d1 = 0;
d2 = -0.5;
k1=0.2;k2 =0.2;
x1 = 2; y1 =1; t1 = pi*1/2;
x2 = 1; y2 =0; t2 = pi*3/2;
v1 = 0.1;w1 = 0.05;v2 = 0;w2 = 0;
rd = f12d;
ld = l12d;
fai = rd;
ko = 1;kf =1;
newx1 = x1+d1*Math.cos(pi-t1);
newy1 = y1-d1*Math.sin(pi-t1);
newx2 = x2+d2*Math.cos(pi-t2);
newy2 = y2-d2*Math.sin(pi-t2);
// x[0] = new Point(int(x1*10),int(y1*10));
//x[1] = new Point(int(x2*10),int(y2*10));
}
//**控制算法
public void ArithmaticForTwo1(){
//for (count=1;count<=countT;count++){
if (count<50){
v1=0.1;
w1=0;}
else if (count<71){
v1=0.1;
w1=-0.05;}
else if (count<110){
v1 = 0.1;
w1=0;}
else if (count<180){
v1=0.1;
w1=-0.05;}
else{
v1=0.1;
w1=0;}
if(ko*kf>0)
sign0 = 1;
else if(ko*kf==0)
sign0 = 0;
else
sign0 = -1;
if ( (sign0 < 0)&&(Math.abs(ko-kf)>30) )
s =!s;
if(s == true)
fai = Math.atan((newy2-newy1)/(newx2-newx1)) - t1;
else
fai = pi+Math.atan((newy2-newy1)/(newx2-newx1)) - t1;
while (fai>=2*pi){ fai = fai-2*pi;}
while (fai<0){fai = fai+2*pi;}
r = fai+t1-t2;
l12 = Math.sqrt((newx1-newx2)*(newx1-newx2)+(newy1-newy2)*(newy1-newy2));
f = rd-fai;
while (f>pi)
f = f-2*pi;
while (f<=-pi)
f = f+2*pi;
System.out.println("fai ="+fai+"\n\n");
System.out.println("l12 ="+l12+"\n\n");
System.out.println("r ="+r+"\n\n");
System.out.println("f ="+f+"\n\n");