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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
   |  
[.....]
	Boule[] boules;
	Image img;
	Dimension dim;
	int sommeil;
	int nbBoules;
 
	//-----------------------
	//---- CONSTRUCTEURS ----
	//-----------------------
	public PanneauBoule(int nbBoules, Image img) {
 
		this.nbBoules = nbBoules;
		sommeil = 10;
		this.img = img;
		setBackground(Color.BLACK);
		setPreferredSize(new Dimension(50,50));
		addComponentListener(this);
		boules = new Boule[nbBoules];
		dim = getPreferredSize();
 
		for(int k=0; k<nbBoules; k++)
			boules[k] = new Boule(dim);
	} // FIN CONSTRUCTEUR
 
	public PanneauBoule(){}
 
	//----------------
	//---- ACIONS ----
	//----------------
 
	public void paintComponent(Graphics g){
 
		g.setColor(getBackground());
		g.fillRect(0, 0, dim.width, dim.height);
 
		for(int k=0; k<boules.length; k++){
 
			g.drawImage(img, (int)boules[k].x, (int)boules[k].y, this);
		}
	}
 
	public void run() {
 
		for(;;) {
 
			for (int k = 0; k < boules.length; k++)
				boules[k].move(dim);
			repaint();
			if (sommeil != 0) {
				try {
					Thread.sleep(sommeil);
				}
				catch(InterruptedException e) {}
			}
		}
	}// FIN RUN
 
	public void componentResized(ComponentEvent e) {
 
		dim = getSize();
 
		for(int k=0; k<boules.length; k++)
			boules[k].moveIntoRect(dim);
	}
 
 
	public void setNbBoules(int nbBoules,Fenetre fenetre,PanneauBoule panneauBoule) 
	{
		this.nbBoules = nbBoules;	
		boules = new Boule[nbBoules];
		dim = panneauBoule.getPreferredSize();
 
		for(int k=0; k<nbBoules; k++)
			boules[k] = new Boule(dim);
	}
[....] | 
Partager