Primera clase:
Código:
Segunda clase:import java.awt.Graphics; import java.awt.Color; public class circulo extends java.applet.Applet{ Circulos cir[]; public void init(){ //el init inicializa el applet this.setSize(1000,1000); cir=new Circulos[100]; for (int i=0;i<100;i++){ cir[i]=new Circulos(this); cir[i]=new Circulos(this); cir[i].start(); } } public void paint (Graphics g){ //g.drawOval pinta el contorno y g.fillOval rellena y g.Rect pinta un rectangulo y g.drawArc pinta un arco, g.drawPoligon pinta un poligono repaint(); for(int i=0;i<100;i++){ g.setColor(new Color((int)(Math.random()*255),(int)(Math.random()*255),(int)(Math.random()*255))); g.fillOval(cir[i].X,cir[i].Y,cir[i].ancho,cir[i].largo); } } }
Código:
import java.awt.Color; public class Circulos extends Thread{ circulo cir; int X,Y,ancho,largo,velocidad; Circulos(circulo cir){ X=0; Y=(int)(Math.random()*600); ancho=(int)(Math.random()*50); largo=(int)(Math.random()*50); velocidad=(int)(Math.random()*100); this.cir=cir; } public void run(){ while(true){ cir.repaint(); try { this.sleep(velocidad); }catch(InterruptedException e){} X++; Y++; } } }