展开全部
没办法了 只能32313133353236313431303231363533e78988e69d8331333337393536注册一个马甲了importjava.awt.*;
importjava.awt.event.*;
importjava.awt.Graphics;
publicclassyes{
publicstaticvoidmain(Stringargs[])
{
Mywindowwin=newMywindow();
Ballqiu1=newBall(5,5);
Threadthread1=newThread(qiu1);
Ballqiu2=newBall(10,5);
Threadthread2=newThread(qiu2);
Ballqiu3=newBall(15,5);
Threadthread3=newThread(qiu3);
thread1.start();
thread2.start();
thread3.start();
}
}
classMywindowextendsFrame{
Mywindow(){
setSize(350,350);
setVisible(true);
setBackground(Color.BLACK);
validate();
addWindowListener(newWindowAdapter(){
publicvoidwindowClosing(WindowEvente){
System.exit(0);
}
});
}
}
classBallextendsMywindowimplementsRunnable
{
intrgb=0;
Colorcolor;
intx,y;
intdx=5,dy=5;
Ball(intx,inty){
this.x=x;
this.y=y;
}
publicvoiddoColor(){
rgb=(int)(Math.random()*0xFFFFFF);
color=newColor(rgb);
}
publicvoidpaint(Graphicsg){
g.setColor(color);
g.fillOval(x,y,50,50);
}
publicvoidrun(){
while(true){
if(x<=0){dx=5;doColor();}
elseif((x+50)>=getWidth()){dx=-5;doColor();}
if(y<=0){dy=5;doColor();}
elseif((y+50)>=getHeight()){dy=-5;doColor();}
x=x+dx;
y=y+dy;
repaint();
try{Thread.sleep(50);}
catch(InterruptedExceptione){;}
}
}
}