这个程序怎么不能显示出 那个正方形和矩形。。。。。 求求大神们 帮帮忙啊
import java.awt.*;
import javax.swing.*;
public class ThreadTest1 extends JFrame implements Runnable {
private Thread t1, t2;
private int x1=-100;
private int x2=-50;
JPanel j=new JPanel();
public ThreadTest1(){
super("多线程1");
setSize(400,300);
setBackground(Color.WHITE);
t1=new Thread(this);
t2= new Thread(this);
t1.start();
t2.start();
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void paint(Graphics g){
Graphics2D comp2D=(Graphics2D)g;
comp2D.setColor(getBackground());//清除
comp2D.fillRect(0, 0, getSize().width, getSize().height);
comp2D.setColor(Color.BLUE);//矩形
comp2D.drawRect(x1, 100, 50, 50);
comp2D.setColor(Color.BLACK);// 圆
comp2D.drawOval(x2, 200, 50, 50);
}
public void run(){
while(true){
if(Thread.currentThread()==t1){
x1+=6;
if(x1>=500){
x1=-100;
repaint();
pause(100);
}else if(Thread.currentThread()==t2){
x2+=4;
if(x2>=500){
x2=-50;
repaint();
pause(120);
}
}
}
}
}
public void pause(int time){
try {
Thread.sleep(time);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String args[]){
new ThreadTest1();
}
}
------解决方案--------------------
那就结贴吧
------解决方案--------------------