package zhoutong;
import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class T extends JApplet implements Runnable{
private Thread thread;
private int cot= 10;
private int x,y;
int dir[][]=new int[][]{{5,5},{-5,5},{-5,-5},{5,-5}};
int d=0;
public void init(){
Random rand = new Random();
x=0;
y=0;
while(x<100||y<100){
x = (int)(Math.random()*800);
y = (int)(Math.random()*800);
}
thread = new Thread(this);
thread.start();
}
public void run(){
while(true){
repaint();
try{
thread.sleep(10);
}catch(Exception e){
System.out.println("system error");
}
}
}
public void paint(Graphics g){
super.paint(g);
g.setColor(Color.red);
//gg.getGraphics().setColor(Color.red);
// g.drawRect(100,100 , 600, 600);
g.fillRect(100, 100, 700, 600);
g.setColor(Color.blue);
//g.drawOval( x, y, 30, 30);
g.fillOval(x, y, 30, 30);
if(x<100||y<100||x>780||y>680){
if(d==0)
d=1;
else if(d==1)
d=2;
else if(d==2)
d=3;
else
d=0;
}
x=x+dir[d][0];
y=y+dir[d][1];
Image ibuffer = createImage(this.getSize().width,this.getSize().height);
Graphics gbuffer = ibuffer.getGraphics();
}
}
applet2
最新推荐文章于 2021-03-11 03:07:21 发布