/** * * @author kooky */ import javax.imageio.*; import javax.swing.*; import java.awt.event.*; import java.awt.image.*; import java.io.*; import java.awt.*; import java.net.*; import java.util.*; import java.net.*; import java.applet.AudioClip; public class ImageMosaique extends JFrame implements ActionListener { private BufferedImage imageCompo; private BufferedImage[] tabImg; private JButton[] tabBut; private ArrayList listBut; private ButtonGroup groupe2; private int nbrePiece; private boolean fin; //donne la fin du jeu private static String lastPicture; //enregistre le nom de la derniere image utilisee public static int manche; public static int partie; private int ok; //++ a chaque morceau correctement places private int nbreFichier; private int ligne, colonne; private String nomImage; private String[] tabList; private JButton butNewGame; private JButton label; private JButton label2; private JMenuBar barreMenu; private JMenu fichier, configuration; private JMenuItem nouveauJeu, sortir; private JCheckBoxMenuItem auto; private JRadioButtonMenuItem deux, quatre, neuf, seize, vingtCinq, trenteSix, quarenteNeuf; private ButtonGroup groupe; private JPanel panHaut; //JPanel d'information private JPanel panBas; //JPanel des morceaux d'image private JPanel panCentral; //JPanel de centre contient panGrille et panImage private JPanel panGrille; //JPanel ou l'on reconstitue l'image private PanneauImage panImage; //image a reconstituer private JScrollPane scroll; // Scrollpane permettant de faire defiler les pieces private Box boxVerticale; // Layout du panel par defaut private int[] gestionClic ={-1,-1}; private LireUnWav jouer = new LireUnWav(); /** * CONSTRUCTEUR 1 DU JEU */ public ImageMosaique() { init(); setVisible(true); } /** * CONSTRUCTEUR 2 DU JEU * @param nbrePiece int */ public ImageMosaique(int nbrePiece) { setNomImage(choixImgHazard()); //Determine l'image à afficher dans panImage this.nbrePiece = nbrePiece; //determine le nombre de morceau du puzzle init(); } /*Differents Getter et Setter de ImageMozaique*/ public int getNbrePiece() { return nbrePiece; } public void setNbrePiece(int nbrePiece) { this.nbrePiece = nbrePiece; } public String getNomImage() { return nomImage; } public void setNomImage(String nomImage) { this.nomImage = nomImage; } public static int getManche() { return manche; } public static void setManche(int manche) { ImageMosaique.manche = manche; } /** * CETTE METHODE LISTE TOUS LES FICHIERS * CONTENUS DANS LE DOSSIER SPECIFIE ET * LES REFERENCES DANS UN TABLEAU tabListe[] * @arg repert File * @parametre repC = Repertoire Courant * @methode ouEstLeJar renvoit le repertoire courant en String */ public void listeDesImages() { try{ String repC = ouEstLeJar(); File repert = new File(repC); tabList = repert.list(); }catch(Exception ex) { ex.printStackTrace(); System.out.println("ATTENTION IL N'Y A PAS DE FICHIER IMAGE COMPATIBLE DANS LE REPERTOIRE COURANT"); System.exit(0); } } /** * CETTE METHODE TIRE AU HAZARD UNE IMAGE (EN .jpg, .png, .gif) * ISSUE DU TABLEAU tabListe[] CREE PAR LA * METHODE listeDesImages() * @return File */ public String choixImgHazard() { int x = 0; listeDesImages(); if(lastPicture == null) { lastPicture = tabList[(x=(int) (10*Math.random()))]; } do{ nbreFichier = tabList.length; x = (int) (nbreFichier*Math.random()); if(tabList[x].equals(lastPicture)==false && tabList[x].endsWith("jpg")==true | tabList[x].endsWith("png")==true) break; }while(true); return tabList[x]; } /** * INITIALISE LA FRAME DU JEU */ public void init() { pack(); //initialise la Frame!!!TOUJOURS AU DEBUT!!! setTitle("Images Mosaique"); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); setLocationRelativeTo(null); setBounds(200,200,800,600); //fixe une taille de depart pour la reduction setExtendedState(MAXIMIZED_BOTH); //maximise la JFrame au demarrage setCursor(new Cursor(Cursor.HAND_CURSOR)); /*Creation barre des menusmenu Fichier et menuItem avec listener */ barreMenu = new JMenuBar(); setJMenuBar(barreMenu); fichier = new JMenu("Fichier"); barreMenu.add(fichier); nouveauJeu = new JMenuItem("Nouveau Jeu"); sortir = new JMenuItem("Sortir"); fichier.add(nouveauJeu); fichier.add(sortir); nouveauJeu.addActionListener(this); sortir.addActionListener(this); nouveauJeu.setToolTipText("Lancer une nouvelle partie"); //infobulle sortir.setToolTipText("Quitter le jeu"); /*creation menu Configuration et menuItem avec listener *dans un GroupButton pour qu'un seul ne soit *selectionne a la fois */ configuration = new JMenu("Configuration"); barreMenu.add(configuration); configuration.setToolTipText("Choisir le nombre de pieces du puzzle");//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! auto = new JCheckBoxMenuItem("Niveau Automatique",true); //true pour auto selectionne!!!!!!!!!!!!!!!!!!!!!!!!!!!! deux = new JRadioButtonMenuItem("2 pieces");//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! quatre = new JRadioButtonMenuItem("4 pieces"); neuf = new JRadioButtonMenuItem("9 pieces"); seize = new JRadioButtonMenuItem("16 pieces"); vingtCinq = new JRadioButtonMenuItem("25 pieces"); trenteSix = new JRadioButtonMenuItem("36 pieces"); quarenteNeuf = new JRadioButtonMenuItem("49 pieces"); configuration.add(auto); configuration.add(deux); configuration.add(quatre); configuration.add(neuf); configuration.add(seize); configuration.add(vingtCinq); configuration.add(trenteSix); configuration.add(quarenteNeuf); auto.addActionListener(this); deux.addActionListener(this); quatre.addActionListener(this); neuf.addActionListener(this); seize.addActionListener(this); vingtCinq.addActionListener(this); trenteSix.addActionListener(this); quarenteNeuf.addActionListener(this); groupe = new ButtonGroup(); groupe.add(auto); groupe.add(deux); groupe.add(quatre); groupe.add(neuf); groupe.add(seize); groupe.add(vingtCinq); groupe.add(trenteSix); groupe.add(quarenteNeuf); auto.setToolTipText("le nombre de piece augmente automatiquement apres 4 reussites"); /*definition du panneau par default ajout des differents panneau */ boxVerticale = Box.createVerticalBox(); this.add(boxVerticale); } public void play(int nbrePiece) { this.nbrePiece = nbrePiece; //determine le nombre de morceau du puzzle setNomImage(choixImgHazard()); //Determine l'image à afficher dans panImage Dimension dim1 = new Dimension(getWidth(),(this.getHeight()*10/100)); Dimension dim2 = new Dimension(getWidth(),(this.getHeight()*50/100)); Dimension dim3 = new Dimension(getWidth(),(this.getHeight()*40/100)+100); panHaut = new JPanel(); panHaut.setLayout(new GridLayout(0,3,10,0)); panBas = new JPanel(); panBas.setLayout(new FlowLayout()); panBas.setBackground(Color.pink); panBas.setPreferredSize(dim3); panBas.setMaximumSize(dim3); panCentral = new JPanel(); panImage = new PanneauImage(); panCentral.setPreferredSize(dim2); panCentral.setMinimumSize(dim2); panGrille = new JPanel(); panGrille.setPreferredSize(panImage.getSize()); scroll = new JScrollPane(); scroll.setColumnHeaderView(panBas); scroll.setRowHeaderView(panBas); scroll.setAutoscrolls(true); scroll.add(panBas); scroll.setViewportView(panBas); scroll.setAutoscrolls(true); EcoutButNewGame ecouteurBNG = new EcoutButNewGame(); butNewGame = new JButton("NOUVELLE PARTIE"); butNewGame.setForeground(Color.green); butNewGame.setFont(new java.awt.Font("Comic Sans MS", 1, 36)); butNewGame.addActionListener(ecouteurBNG); label = new JButton("PARTIE : "+partie); label.setFont(new java.awt.Font("Comic Sans MS", 1, 36)); label.setBackground(Color.blue); label.setForeground(Color.pink); label.setEnabled(false); label2 = new JButton("RESTE : "+ok+" / "+getNbrePiece()); label2.setFont(new java.awt.Font("Comic Sans MS", 1, 36)); label2.setBackground(Color.yellow); label2.setForeground(Color.blue); label2.setEnabled(false); panHaut.add(label);panHaut.add(butNewGame);panHaut.add(label2); panCentral.setLayout(new GridLayout(0,2)); panCentral.add(panImage); ligne = (int) Math.sqrt(nbrePiece); colonne = (int) Math.sqrt(nbrePiece); panGrille.setLayout(new GridLayout(colonne,ligne)); tabBut = new JButton[nbrePiece]; listBut = new ArrayList(nbrePiece); tabImg = new BufferedImage[nbrePiece]; setVisible(true); //LA JFRAME EST RENDUE VISIBLE ICI (evite Pointeur null) EcoutGrille ecouteur = new EcoutGrille(); //DECLARATION DE L'ECOUTEUR DE LA GRILLE /*Creation des boutons dans un tableau "tabBut" de la grille de panGrille ou le puzzle est reconstitue*/ for(int i = 0; i<=nbrePiece-1; i++) { tabBut[i] = new JButton(); tabBut[i].setActionCommand(String.valueOf(i)); tabBut[i].addActionListener(ecouteur); //CHAQUE BOUTTON DE LA GRILLE DISPOSE D'UN ECOUTEUR tabBut[i].setBackground(Color.black); panGrille.add(tabBut[i]); } EcoutMorceau ecouteur2 = new EcoutMorceau(); groupe2 = new ButtonGroup(); /*Creation des bouton morceau de l'image dans panBas inseres dans une ArrayList "listBut"*/ for(int i = 0; i<=nbrePiece-1; i++) { listBut.add(new JButton()); listBut.get(i).setActionCommand(String.valueOf(i)); listBut.get(i).addActionListener(ecouteur2); //CHAQUE BOUTTON (MORCEAU) DISPOSE D'UN ECOUTEUR groupe2.add(listBut.get(i)); panBas.add(listBut.get(i)); } panCentral.add(panGrille); /*Ajout des differents panneau au panneau principal(boxVerticale)*/ boxVerticale.add(panHaut); boxVerticale.add(panCentral); boxVerticale.add(scroll); validate(); /*recuperation de l'image au dimension du panImage *on demande au panel de se dessiner sur les graphics de l'image*/ imageCompo = new BufferedImage(panImage.getWidth(), panImage.getHeight(),BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = imageCompo.createGraphics(); panImage.printAll(g2d); g2d.dispose(); /*Decoupe de l'image de panImage : chaque bouton de la list "listBut" recupere *un morceau (en ImageIcon()) egal a la position de chaque *bouton de "pangrille" (puisque panGrille == panImage), *c'est comme si on decoupe le "panImage" en fonction de "panGrille"*/ for(int i = 0; i<=nbrePiece-1; i++) { tabImg[i] = new BufferedImage(tabBut[1].getWidth(), tabBut[1].getHeight(), BufferedImage.TYPE_INT_RGB); tabImg[i].getGraphics().drawImage(imageCompo, 0, 0, tabBut[i].getWidth(), tabBut[i].getHeight() , tabBut[i].getX(), tabBut[i].getY(), (tabBut[i].getX()+tabBut[i].getWidth()) ,(tabBut[i].getY()+tabBut[i].getHeight()),null); listBut.get(i).setIcon(new ImageIcon(tabImg[i])); listBut.get(i).setPreferredSize(tabBut[1].getSize()); listBut.get(i).setMinimumSize(tabBut[1].getSize()); listBut.get(i).revalidate(); } /*Melange l'ordre d'affichage des morceaux d'image dans le panBas*/ Component tmp = new JButton(); for(int i = 0; i <= listBut.size()-1;i++) { int x = 0; x = (int) (nbrePiece*Math.random()); tmp = panBas.getComponent(x); panBas.remove(x); panBas.add(tmp); } if(partie==0) lastPicture = getNomImage(); /*Information de debugage et de control*/ System.out.println("\n§§§§§§§§§§§§§§§§§§§§ Information de debugage et de control §§§§§§§§§§§§§§§§§§§§§§"); System.out.println("Le precedant fichier image etait : "+lastPicture); System.out.println("Le fichier image utilise est : " + getNomImage()); System.out.println("Taille des cases de la grille : " + tabBut[0].getSize()); System.out.println("Taille des morceau d'image de panBas : " + listBut.get(0).getSize()); System.out.println("Taille du panImage : "+panImage.getSize()); System.out.println("taille de panGrille : "+panGrille.getSize()); System.out.println("Nbre d'element dans le tableau tabBut : " + tabBut.length); System.out.println("Nbre d'elements dans l'ArrayList listBut : "+ listBut.size()); System.out.println("Nbre de manches : " + getManche()); System.out.println("Nbre de morceau decouvert ok = "+ok); System.out.println("Valeur de fin : "+ fin); System.out.println("\n"); //************************************************************************************ /**Classe anonyme permettant de connaitre la taille * de la fenetre a chaque clic * @Override par MouseAdaptater MouseListener */ addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { //System.out.println("Taille de la fenetre ------"+ getSize()); } }); } /** *************** GERE LES EVENEMENT ACTION **************************** * @param e EVENT */ public void actionPerformed(ActionEvent e) { Object source = e.getSource(); fin = false; ok = 0; if(source == nouveauJeu) { System.out.println("Action sur Nouveau Jeu"); fin = false; ok = 0; if(auto.isSelected()) { partie = 0; manche = 0; boxVerticale.removeAll(); manche++; System.out.println("*********** Nbre de Morceau : " + getNbrePiece()+" ***********"); if(manche<=4){ play(2);} else if(manche<=8){ play(4);} else if(manche<=12){ play(9);} else if(manche<=16){ play(16);} else if(manche<=20){ play(25);} else if(manche<=24){ play(36);} else if(manche<=28){ play(49);} else {setManche(0);System.out.println("remise a 0");} butNewGame.setText("CONTINUER"); label.setText("MANCHE : "+manche); } if(deux.isSelected()){ partie = 0; manche = 0; boxVerticale.removeAll(); play(2); } if(quatre.isSelected()) { partie = 0; manche = 0; boxVerticale.removeAll(); play(4); } if(neuf.isSelected()) { partie = 0; manche = 0; boxVerticale.removeAll(); play(9); } if(seize.isSelected()) { partie = 0; manche = 0; boxVerticale.removeAll(); play(16); } if(vingtCinq.isSelected()) { partie = 0; manche = 0; boxVerticale.removeAll(); play(25); } if(trenteSix.isSelected()) { partie = 0; manche = 0; boxVerticale.removeAll(); play(36); } if(quarenteNeuf.isSelected()) { partie = 0; manche = 0; boxVerticale.removeAll(); play(49); } } if(source == sortir) { System.out.println("action sur Sortir"); String text = ""; text = JOptionPane.showInputDialog(null,"TAPEZ OK POUR SORTIR" ,"CONTROLE DE SORTIE" ,JOptionPane.WARNING_MESSAGE); if(text.compareTo("ok") == 0 || text.compareTo("OK") == 0) { System.out.println("Au revoir!"); System.exit(0); } } if(source == auto) { partie = 0; manche = 0; System.out.println("action sur Niveau Automatique"); boxVerticale.removeAll(); setManche((getManche()+1)); play(2); butNewGame.setText("CONTINUER"); label.setText("MANCHE : "+manche); butNewGame.setEnabled(false); } if(source == deux) { partie = 0; manche = 0; System.out.println("action sur 2"); //dispose(); boxVerticale.removeAll(); play(2); } if(source == quatre) { partie = 0; manche = 0; System.out.println("action sur 4"); //dispose(); boxVerticale.removeAll(); play(4); } if(source == neuf) { partie = 0; manche = 0; System.out.println("action sur 9"); //dispose(); boxVerticale.removeAll(); play(9); } if(source == seize) { partie = 0; manche = 0; System.out.println("action sur 16"); //dispose(); boxVerticale.removeAll(); play(16); } if(source == vingtCinq) { partie = 0; manche = 0; System.out.println("action sur 25"); //dispose(); boxVerticale.removeAll(); play(25); } if(source == trenteSix) { partie = 0; manche = 0; System.out.println("action sur 36"); //dispose(); boxVerticale.removeAll(); play(36); } if(source == quarenteNeuf) { partie = 0; manche = 0; System.out.println("action sur 49"); //dispose(); boxVerticale.removeAll(); play(49); } } /** * CETTE METHODE PERMET DE CONNAITRE OU SE TROUVE * UN JAR OU UNE CLASS SUR L'OS. * @return String URL du jar ou class */ public String ouEstLeJar() { String path = getClass().getName() + ".class"; URL url = getClass().getResource(path); try{ path = URLDecoder.decode(url.toString(), "UTF-8"); }catch(Exception ex) { ex.printStackTrace();} // suppression de la classe ou du jar du path de l'url int index = path.lastIndexOf("/"); path = path.substring(0, index); if (path.startsWith("jar:file:")) { // suppression de jar:file: de l'url d'un jar // ainsi que du path de la classe dans le jar index = path.indexOf("!"); path = path.substring(9, index); } else { // suppresion du file: de l'url si c'est une classe en dehors d'un jar // et suppression du path du package si il est present. path = path.substring(5, path.length()); Package pack = getClass().getPackage(); if (null != pack) { String packPath = pack.toString().replace('.', '/'); if (path.endsWith(packPath)) { path = path.substring(0, (path.length() - packPath.length())); } } } //*********** PAS UTILISE ICI ***************** String tmp = ""; /*StringBuffer monUrl = new StringBuffer(path); int x = monUrl.lastIndexOf("/"); monUrl.delete(x+1, path.length()); tmp = monUrl.toString(); //adresse = "file://"+tmp; path = tmp;*/ System.out.println("path = "+path); return path; } class EcoutButNewGame implements ActionListener { public void actionPerformed(ActionEvent e) { fin = false; ok = 0; if(auto.isSelected()) { boxVerticale.removeAll(); manche++; System.out.println("*********** Nbre de Morceau : " + getNbrePiece()+" ***********"); if(manche<=4){ play(2);} else if(manche<=8){ play(4);} else if(manche<=12){ play(9);} else if(manche<=16){ play(16);} else if(manche<=20){ play(25);} else if(manche<=24){ play(36);} else if(manche<=28){ play(49);} else {setManche(0);System.out.println("remise a 0");} butNewGame.setText("CONTINUER"); label.setText("MANCHE : "+manche); butNewGame.setEnabled(false); } if(deux.isSelected()){ boxVerticale.removeAll(); play(2); } if(quatre.isSelected()) { boxVerticale.removeAll(); play(4); } if(neuf.isSelected()) { boxVerticale.removeAll(); play(9); } if(seize.isSelected()) { boxVerticale.removeAll(); play(16); } if(vingtCinq.isSelected()) { boxVerticale.removeAll(); play(25); } if(trenteSix.isSelected()) { boxVerticale.removeAll(); play(36); } if(quarenteNeuf.isSelected()) { boxVerticale.removeAll(); play(49); } } } /****************************************************************************************************** *This "inner" class give the action of the clic on the button morceau *CF PROGRAMMER EN JAVA */ class EcoutMorceau implements ActionListener { public void actionPerformed(ActionEvent e) { String commande = e.getActionCommand(); //ON RECUP L'EVENEMENT(e) int num = Integer.parseInt(commande); //CONVERSION STRING -> INT gestionClic[1] = num; if(gestionClic[0] != -1) { if(gestionClic[1] == gestionClic[0]) { tabBut[num].setIcon(listBut.get(num).getIcon()); tabBut[num].validate(); listBut.get(num).setVisible(false); gestionClic[1]=-1; gestionClic[0]=-1; ok++; label2.setText("RESTE : "+ok+" / "+getNbrePiece()); if(ok==nbrePiece) fin = true; } else { jouer.Bad(); gestionClic[1]=-1; gestionClic[0]=-1; } /*Quand tout les morceau ont ete correctement replace*/ if(fin==true) { lastPicture = getNomImage(); partie++; PanneauImage panVic = new PanneauImage("victoire.gif"); Dimension dimVic = new Dimension(200,200); panVic.setSize(dimVic); panVic.setPreferredSize(dimVic); panVic.setMinimumSize(dimVic); panBas.add(panVic); jouer.Victoire(); butNewGame.setEnabled(true); } } } } /****************************************************************************************************** *This "inner" class give the action of the clic on the button in the grille *CF PROGRAMMER EN JAVA */ class EcoutGrille implements ActionListener { public void actionPerformed(ActionEvent e) { String commande = e.getActionCommand(); //ON RECUP L'EVENEMENT(e) int num = Integer.parseInt(commande); //CONVERSION STRING -> INT gestionClic[0] = num; if(gestionClic[1] != -1) { if(gestionClic[0] == gestionClic[1]) { tabBut[num].setIcon(listBut.get(num).getIcon()); tabBut[num].validate(); listBut.get(num).setVisible(false); gestionClic[1]=-1; gestionClic[0]=-1; ok++; label2.setText("RESTE : "+ok+" / "+getNbrePiece()); if(ok==nbrePiece) fin = true; } else { jouer.Bad(); gestionClic[0]=-1; gestionClic[1]=-1; } /*Quand tout les morceau ont ete correctement replace*/ if(fin==true) { partie++; lastPicture = getNomImage(); PanneauImage panVic = new PanneauImage("victoire.gif"); Dimension dimVic = new Dimension(150,150); panVic.setSize(dimVic); panVic.setPreferredSize(dimVic); panVic.setMinimumSize(dimVic); panBas.add(panVic ); jouer.Victoire(); butNewGame.setEnabled(true); } } } } /****************************************************************************** * Ici en Classe Interne * CF DEVELOPPEZ.COM CODE SOURCE * AFFICHE .GIF .JPG .PNG(?) * CETTE CLASS PERMET D'ADAPTER LA TAILLE DE L'IMAGE AU COMPOSANT QUELLE * SOIT + GRANDE OU + PETITE QUE LE COMPOSANT(PANNEAU) * A L'ORIGINE UN ZOOM ETE UTLISAIT SI L'IMAGE ETE TROP GRANDE * ET L'IMAGE ETAIT CENTREE QUAND + PETITE QUE LE COMPOSANT * This class works also if the picture is in a jar file. *!!!!!!!!!!!!!!!"ImagePerso doit extends JPanel pour afficher un gif!!!!!!!!! *!!!!!!!!!!!!!!!!!!!!!!extends JButton peu juste afficher jpg!!!!!!!!!!!!!!!! */ class PanneauImage extends JPanel { private Image img; private BufferedImage imageCompo; public String file; /** * load a image *@arg File = ????????.gif/jpg/png */ public PanneauImage() { file = getNomImage(); img = new ImageIcon(getClass().getResource(file)).getImage(); repaint(); } /** * Loads the specified image, which must be a JPG, a GIF, or a PNG. * @param file the file to load */ public PanneauImage(String file) { this.file = file; img = new ImageIcon(getClass().getResource(file)).getImage(); repaint(); } /** * * @return STRING IMAGE * @author kooky */ public String getImage() { return file; } /** *@Override JPanel */ @Override public void paintComponent(Graphics g) { super.paintComponent(g); if (img == null) return; g.drawImage(img, 0, 0, getWidth(), getHeight(), this);//IF + BOOLEAN A ETE SUPRIMER imageCompo = new BufferedImage(getWidth(),getHeight(),BufferedImage.TYPE_INT_RGB); } } //import java.net.*; //import java.applet.AudioClip; class LireUnWav extends java.applet.Applet { // création des 3 objets AudioClip AudioClip ok; AudioClip bad; AudioClip victoire; AudioClip supVictoire; /************************************************************************************************** * joue un son quand l'action demandee * est reussie. */ public void OK() { // on indique quels sont les fichiers à lire dans une URL try{ File fSon = new File("chimes.wav"); URI uri = fSon.toURI(); URL emplacement = uri.toURL(); System.out.println("Emplacement--OK ->"+emplacement); ok = newAudioClip(emplacement); ok.play(); //lit une fois le wav Thread.sleep(500); //pause pour lire entierement le wav 0.5 secondes }catch(Exception ex) { ex.printStackTrace(); } } /************************************************************************************************** * joue un son quand l'action demandee * a echoue. */ public void Bad() { // on indique quels sont les fichiers à lire dans une URL try{ File fSon = new File("notify.wav"); URI uri = fSon.toURI(); URL emplacement = uri.toURL(); System.out.println("Emplacement-bad ->"+emplacement); bad = newAudioClip(emplacement); bad.play(); //lit 1 fois Thread.sleep(500); //pause pour lire entierement le wav 0.5 secondes }catch(Exception ex) { ex.printStackTrace(); } } /************************************************************************************************** * joue un son quand l'application s'acheve * avec succee */ public void Victoire() { // on indique quels sont les fichiers à lire dans une URL try{ File fSon = new File("tada.wav"); URI uri = fSon.toURI(); URL emplacement = uri.toURL(); System.out.println("Emplacement--Victoire ->"+emplacement); victoire = newAudioClip(emplacement); victoire.play(); //lit 1 fois Thread.sleep(1000); //pause pour lire entierement le wav 2 secondes }catch(Exception ex) { ex.printStackTrace(); } } } /************************************************************************** * METHODE MAIN DU JEU, LANCE LE JEU * @param arg = AUCUN */ public static void main(String[] arg) { ImageMosaique im = new ImageMosaique(); } }