JAVA牛人来看一看这段JAVA代码哪里出错了(在我qq空间里)

来源:百度知道 编辑:UC知道 时间:2024/05/25 01:05:15
代码太长了只好放在qq空间里了

这段程序的功能:一个球在一个面板上弹跳,另一个球在面板的另一个部分弹跳(bounce).(每个球有两个按钮:开始1,停止1;开始2,停止2).使用了线程的概念.我的疑问是:Balls和Ball这两个类怎么区别?(源代码来自参考书,显然有错误,敬请牛人帮忙指正)

http://user.qzone.qq.com/964916598
代码是在空间的日志里......

//balls是面板,ball是控球的线程
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class Balls extends JFrame implements ActionListener {
private JButton go1,go2,stop1,stop2;
private JPanel panel1,panel2;
private Ball ball1,ball2;
public static void main(String[] args){
Balls frame = new Balls ();
frame.setSize(500,150);
frame.createGUI();
frame.setVisible(true);
}
private void createGUI(){
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container window =getContentPane();
window.setLayout(new FlowLayout());
go1 = new JButton("go 1");
window.add(go1);
go1.addActionListener(this);

stop1= new JButton("stop 1");
window.add(stop1);
stop1.addActionListener(this);
panel1= new JPanel();
panel1.setPreferredSize(new Dimension(100,100));
panel1.setBackground(Color.whi