package bazooka; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.io.IOException; import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JPanel; public class PanelPrincipale extends JPanel { private JButton [] bouton; private JButton boutExit; private NomDeBouton unNom = new NomDeBouton (); private CheminDeBouton unChemin = new CheminDeBouton (); public PanelPrincipale (NomDeBouton aNom) { this.unNom = aNom; } public PanelPrincipale (CheminDeBouton aChemin) { this.unChemin = aChemin; } private int x = this.unNom.getListNom ().size () - 1; public PanelPrincipale () { this.setLayout (new GridLayout (0, 3)); bouton = new JButton [x + 1]; for (int i = 0; i <= x; i ++ ) { bouton [i] = new JButton (String.valueOf (this.unNom.getListNom ().get (i))); bouton [i].addActionListener (new ActionLancement (this.unNom.getListNom ().get (i))); this.add (bouton [i]); } boutExit = new JButton ("Quitter"); boutExit.addActionListener (new ActionExit ()); this.add (this.boutExit); this.setVisible (true); } public JButton [] getBouton () { return bouton; } public void setBouton (JButton [] bouton) { this.bouton = bouton; } public JButton getBoutExit () { return this.boutExit; } private class ActionLancement extends AbstractAction { public ActionLancement (String texte) { } public void actionPerformed (ActionEvent aE) { for (int i = 0; i < x; i ++ ) { if (aE.getActionCommand () == unNom.getListNom ().get (i)) { try { Runtime run = Runtime.getRuntime (); run.exec (unChemin.getListChemin ().get (i)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace (); } } } } } private class ActionExit extends AbstractAction { public ActionExit () { } public void actionPerformed (ActionEvent aE) { if (aE.getSource () == boutExit) { System.exit ( - 1); } } } }