/* Jeu de "pétages" de Ballons, illustration de création d'objets et d'affichage graphique sélectif */ import java.awt.Graphics; import java.awt.Color; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import javax.swing.JFrame; import javax.swing.JRadioButton; import javax.swing.ButtonGroup; import javax.swing.JPanel; import javax.swing.JComponent; public class PetageDeBalounes { private static int affichage = 2; // mode d'affichage 0, 1 ou 2 private static JRadioButton [] bs; private static String [] bn = {"Lent","Moyen","Rapide"}; // donne un entier au hasard dans l'intervalle [a,b] private static int hasard(int a, int b){ return (int)(Math.random()*(b-a+1))+a; } private static class BalounesPanel extends JPanel implements MouseListener{ private int nb, nbDebut, // nombre de balounes xDebut, yDebut, xFin, yFin; // dimension de la fenêtre private Effacable[] b; // tableau des Balounes // temps du début d'exécution et de la dernière Baloune crevée private long tempsDebut,tempsClic; private Color [] couleurs = {Color.red,Color.green,Color.blue,Color.yellow, Color.cyan, Color.magenta,Color.orange}; BalounesPanel(int nb,int largeur,int hauteur){ // créer l'affichage this.nb = nb; nbDebut = nb; b = new Effacable[nb]; xDebut = 0; yDebut=20; xFin = largeur; yFin = hauteur; Effacable.setFondEcran(getBackground()); // création des Ballons for(int k=0;k0) for (int i=0;i0){ tempsClic=System.currentTimeMillis(); for(int i=nb-1;i>=0;i--){ if(b[i].contient(x,y)){ System.out.println("Creve "+ i); Effacable crevee=b[i]; nb--; if(nb>0){ // enlever la Baloune crevée for(int j=i;j