一个JAVA题

来源:百度知道 编辑:UC知道 时间:2024/09/23 02:28:38
桌球子弹。。。。编好了就是不跑。。。。高手看看怎么修改
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
public class Test6 extends Thread {
Table table=null;
int x,y,vx,vy;
Test6(int x,int y,int vx,int vy)
{
this.x=x;
this.y=y;
this.vx=vx;
this.vy=vy;

}
public void run()
{
while(true)
{
if(x>(table.getSize().width)-25||(x<0))
vx=vx*-1;
if(y>(table.getSize().width)-25||(y<0))
vy*=-1;
x+=vx;
y+=vy;
try
{
Thread.sleep(100);

}
catch(Exception e)
{

}
table.repaint();
}

}
public void draw (Graphics g)
{
g.setColor(Color.BLACK);
g.fillOval(x, y, 30, 30);
g.setColor(Color.white);
g.fillOval(x+5, y+5, 8, 6);

}
}
class Table exten

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class Test extends Thread {
Table table = null;
int x, y, vx, vy;

Test(int x, int y, int vx, int vy, Table table) {
this.x = x;
this.y = y;
this.vx = vx;
this.vy = vy;
this.table = table;//注意此处

}

public void run() {
while (true) {
if (x > (table.getSize().width) - 25 || (x < 0))
vx = vx * -1;
if (y > (table.getSize().width) - 25 || (y < 0))
vy *= -1;
x += vx;
y += vy;
try {
Thread.sleep(100);

} catch (Exception e) {

}
table.repaint();
}

}

public void draw(Graphics g) {
g.setColor(Color.BLACK);
g.fillOval(x, y, 30, 30);
g.setColor(Color.white);
g.fillOval(x + 5, y + 5, 8, 6);

}
}

import java.awt.Button;
import java.awt.Colo