!!~帮我看看这个Java小程序!!!

请给我看一下!当小球不动后,我在单击“复位”按钮后可以让小球回到原位,单击事件怎么写!还有如果可以的话帮我加个停止按钮,在单击时可以随时终止小球运动!
谢谢了~~

[code="java"]import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Line2D;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class BallBall extends JFrame
{

public BallBall()                  //TwoBall构造
{
    super("演示");
    this.setSize(1000, 750);
    this.setLocation(20, 20);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);  

    Ball jpanel= new Ball();
    this.add(jpanel);

    this.setVisible(true);
}


class Ball extends JPanel implements ActionListener
{
    private int T; 
    double v1;                  //上抛初速         5000<v1<11000
    double v2; 
    double x21, y21, x22, y22; // 斜抛坐标
    double x1,y1;             //上抛运动坐标
    double g=9.8; 
    int Q=10000;
    Image a,b;

    private JTextField time;
    private JTextField yv;
    private JTextField xv;
    private JButton start,back;
    private Thread thread1;
    private Thread thread2;

    public Ball()    
    {
         this.setBackground(Color.WHITE);

         this.T=1000;
         this.v1 = 8000;
         this.v2=7000;
         this.x1=200000;
         this.y1=6200000;
         this.x21=200000;
         this.y21=60000000;

         JPanel Control=new JPanel();
         this.add(Control,BorderLayout.NORTH);

         JLabel TIME=new JLabel("时间");
         Control.add(TIME);
         time=new JTextField("1000");
         Control.add(time);


         JLabel YV=new JLabel("              上抛初速度");
         Control.add(YV);
         yv=new JTextField("8000");
         Control.add(yv);


         JLabel XV =new JLabel("             水平方向初速度");
         Control.add(XV);
         xv=new JTextField("7000");
         Control.add(xv);


         start = new JButton("启动");
         Control.add(start);
         start.addActionListener(this);

         back= new JButton("复位");
         Control.add(back);
         back.addActionListener(this);

         thread1=new Thread(new Ball1());
         thread1=new Thread(new Ball2());

    }


    public void paint(Graphics g)         //绘图
    {

            super.paint(g);                

            Baseline(g);     //画坐标线  基线

            paintUP(g);         //上抛运动

            paintXP(g);        //斜抛
            paintXPline((Graphics2D) g);      //画斜抛轨迹

            this.repaint();

    }



    private void Baseline(Graphics g) 
    {

        g.setColor(Color.black);  //画2条基准线,方便观察
        g.drawLine(20, 650, 20, 100); 
        g.setColor(Color.black);
        g.drawLine(20,650, 880, 650); 


    }


    private void paintUP(Graphics g)  //画小球上抛运动
     {

         g.drawOval((int)(x1/Q),(int)(y1/Q), 25, 25);
     }

    private void paintXP(Graphics g)  //画上小球斜抛抛运动
     {
        g.drawOval((int)(x21/Q),(int)(y21/Q), 25, 25);

     }



    private List<Line2D> towList = new ArrayList<Line2D>();
     private void paintXPline(Graphics2D g)                    //画斜抛运动的轨迹
     {


         towList.add(new Line2D.Double(x21/Q+5,y21/Q,x22/Q,y22/Q));//+4加粗效果


         g.setPaint(Color.BLUE);   

        for (Line2D l : towList)         
         {
             g.draw(l);
         }
     }

    class Ball1 implements Runnable        //线程1  控制小球上抛
    {

        int t1=0;


        public void run()
        {
            while (t1<T)
            {

                t1+=10;
                x1 = 30*Q;

                y1 = 600*Q-v1 * t1+0.5 * g * t1*t1;
                try 
                {
                    Thread.sleep(100);
                } 
                catch (InterruptedException e) 
                {
                    e.printStackTrace();
                }
           }
        }
    }


    class Ball2 implements Runnable        //线程2 控制小球斜抛
    {
        int t2=0;


        public void run()
        {
            while (t2<T)
            {

                t2+=10;

                x22 =30*Q+v2 * t2;                           
                y22 =650*Q-v1 * t2+0.5 * g * Math.pow(t2, 2);

                x21 = x22;
                y21 = y22;

                try 
                {
                    Thread.sleep(100);
                } 
                catch (InterruptedException e) 
                {
                    e.printStackTrace();
                }
            }
        }
    }


    public void actionPerformed(ActionEvent e) 
    {

        if(e.getSource()==start)
        {
            thread1=new Thread(new Ball1());
            thread2=new Thread(new Ball2());
            thread1.start();
            thread2.start();

            T=Integer.parseInt(time.getText());
            v1=Integer.parseInt(yv.getText());
            v2=Integer.parseInt(xv.getText());



            start.setEnabled(false);
            back.setEnabled(true);
        }
        if(e.getSource()==back)
        {    
            this.repaint();
            start.setEnabled(true);
            back.setEnabled(false);
        }
    }


}

 public static void main(String args[])   //main函数
    {

        new BallBall();

    }

}

[/code]

楼主,给你弄好了,给你改了下程序的架构,把actionlistener弄到最外层frame框架那里了,感觉好点,如果不满意可以改回来,加上了暂停,恢复按钮,复位弄好了,不过复位后屏幕没有清除,上班了,没时间弄了,呵呵,楼主可以自己弄下,锻炼锻炼呀,嘿嘿,加油!

[code="java"]import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.Graphics;

import java.awt.Graphics2D;

import java.awt.Image;

import java.awt.Toolkit;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.geom.Line2D;

import java.util.ArrayList;

import java.util.List;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JTextField;

public class BallBall extends JFrame implements ActionListener
{

Ball jpanel;
private JTextField time;

private JTextField yv;

private JTextField xv;

private JButton start,back,stop,recover;

private Thread thread1;

private Thread thread2;
int T;

double v1; //上抛初速 5000<v1<11000

double v2;

double x21, y21, x22, y22; // 斜抛坐标

double x1,y1; //上抛运动坐标

double g=9.8;

int Q=10000;

Image a,b;

public BallBall() //TwoBall构造

{

super("演示");

this.setSize(1000, 750);

this.setLocation(20, 20);

this.setDefaultCloseOperation(EXIT_ON_CLOSE);

this.T=1000;

this.v1 = 8000;

this.v2=7000;

this.x1=200000;

this.y1=6200000;

this.x21=200000;

this.y21=60000000;

    JPanel Control=new JPanel();   
    this.add(Control,BorderLayout.NORTH);   

    JLabel TIME=new JLabel("时间");   
    Control.add(TIME);   
    time=new JTextField("1000");   
    Control.add(time);   


    JLabel YV=new JLabel("              上抛初速度");   
    Control.add(YV);   
    yv=new JTextField("8000");   
    Control.add(yv);   


    JLabel XV =new JLabel("             水平方向初速度");   
    Control.add(XV);   
    xv=new JTextField("7000");   
    Control.add(xv);   


    start = new JButton("启动");   
    Control.add(start);   
    start.addActionListener(this);   

    stop =  new JButton("暂停");
    Control.add(stop);   
    stop.addActionListener(this);  

    recover =  new JButton("恢复");
    Control.add(recover);   
    recover.addActionListener(this); 

    back= new JButton("复位");   
    Control.add(back);   
    back.addActionListener(this);        
    thread1=new Thread(new Ball1());   
    thread2=new Thread(new Ball2());   
    jpanel= new Ball();   
    this.add(jpanel);  
    this.setVisible(true);   
}   


class Ball extends JPanel    
{   
  public Ball()       
    {   
         this.setBackground(Color.WHITE);    
    }   


    public void paint(Graphics g)         //绘图   
    {   

            super.paint(g);                   

            Baseline(g);     //画坐标线  基线   

            paintUP(g);         //上抛运动   

            paintXP(g);        //斜抛   
            paintXPline((Graphics2D) g);      //画斜抛轨迹   

            this.repaint();   

    }   



    private void Baseline(Graphics g)    
    {   

        g.setColor(Color.black);  //画2条基准线,方便观察   
        g.drawLine(20, 650, 20, 100);    
        g.setColor(Color.black);   
        g.drawLine(20,650, 880, 650);    


    }   


    private void paintUP(Graphics g)  //画小球上抛运动   
     {   

         g.drawOval((int)(x1/Q),(int)(y1/Q), 25, 25);   
     }   

    private void paintXP(Graphics g)  //画上小球斜抛抛运动   
     {   
        g.drawOval((int)(x21/Q),(int)(y21/Q), 25, 25);   

     }   



    private List<Line2D> towList = new ArrayList<Line2D>();   
     private void paintXPline(Graphics2D g)                    //画斜抛运动的轨迹   
     {   


         towList.add(new Line2D.Double(x21/Q+5,y21/Q,x22/Q,y22/Q));//+4加粗效果   


         g.setPaint(Color.GRAY);      

        for (Line2D l : towList)            
         {   
             g.draw(l);   
         }   
     }   
 }  

class Ball2 implements Runnable        //线程2 控制小球斜抛   
{   
    int t2=0;   


    public void run()   
    {   
        while (t2<T)   
        {   

            t2+=10;   

            x22 =30*Q+v2 * t2;                              
            y22 =650*Q-v1 * t2+0.5 * g * Math.pow(t2, 2);   

            x21 = x22;   
            y21 = y22;   

            try    
            {   
                Thread.sleep(100);   
            }    
            catch (InterruptedException e)    
            {   
                e.printStackTrace();   
            }   
        }   
    }   
}   
class Ball1 implements Runnable        //线程1  控制小球上抛   
{   

    int t1=0;   


    public void run()   
    {   
        while (t1<T)   
        {   

            t1+=10;   
            x1 = 30*Q;   

            y1 = 600*Q-v1 * t1+0.5 * g * t1*t1;   
            try    
            {   
                Thread.sleep(100);   
            }    
            catch (InterruptedException e)    
            {   
                e.printStackTrace();   
            }   
       }   
    }   
}   
public void actionPerformed(ActionEvent e)    
{   

    if(e.getSource()==start)   
    {   
        thread1=new Thread(new Ball1());   
        thread2=new Thread(new Ball2());   
        thread1.start();   
        thread2.start();   

        T=Integer.parseInt(time.getText());   
        v1=Integer.parseInt(yv.getText());   
        v2=Integer.parseInt(xv.getText());   



        start.setEnabled(false);   
        back.setEnabled(true);   
    }   
    if(e.getSource()==back)   
    {         
        start.setEnabled(true);   
        back.setEnabled(false); 
        thread1.stop();   
        thread2.stop();  

// this.jpanel=new Ball(); //这里加清除屏幕东西的代码就OK了
// this.add(jpanel);
// this.repaint();
}

if(e.getSource()==stop)
{
thread1.suspend();

thread2.suspend();
}
if(e.getSource()== recover)
{
thread1.resume();
thread2.resume();
}
}

public static void main(String args[]) //main函数

{

        new BallBall();   

    }   

} [/code]

挺有意思,呵呵,帮你看看