1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| public class Descar extends Applet implements Runnable {
private int blue, red, green, rgb, i=0;
private int longueur,hauteur=0;
private int x,y=0;
private boolean arret=false;
public void start(){
this.arret=false;
(new Thread(this)).start();}
public void stop(){
this.arret=true;
}
public void run(){
while(true){
this.paint(this.getGraphics());
try{
Thread.sleep(5000);
}
catch (Exception e){
}
if(this.arret==true){
return;
}
}
}
public void changeCoul(){
rgb=255*(int)Math.random();
}
public void changeDim(){
x=100*(int)Math.random();
y=100*(int)Math.random();
longueur=hauteur=30*(int)Math.random();
}
public void paint(Graphics ga){
this.changeCoul();
red=rgb;
this.changeCoul();
blue=rgb;
this.changeCoul();
green=rgb;
this.changeDim();
ga.setColor(new Color(red, green, blue));
ga.drawRect(x,y,longueur,hauteur);
ga.fillRect(x,y,longueur,hauteur);
}
} |
Partager