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 79 80 81 82 83
|
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.*;
public class Menu extends JPanel implements ActionListener{
private JButton quete;
private JButton perso;
private JButton invent;
private JButton map;
/*JFrame principale */
private MainGui Mg;
/*liste de mes listener*/
private ArrayList monListenerPersoList;
/*constructeur Menu*/
public Menu(MainGui gui) {
Mg = gui;
addMonListenerPerso(Mg);
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
map = new JButton("Monde");
map.setMnemonic('m');
map.addActionListener(this);
quete = new JButton("Journal");
quete.setMnemonic('j');
quete.addActionListener(this);
invent = new JButton("Inventaire");
invent.setMnemonic('i');
invent.addActionListener(this);
perso = new JButton("Caractéristiques");
perso.setMnemonic('c');
perso.addActionListener(this);
add(Box.createRigidArea(new Dimension(0, 25)));
add(map);
add(Box.createRigidArea(new Dimension(0, 25)));
add(quete);
add(Box.createRigidArea(new Dimension(0, 25)));
add(invent);
add(Box.createRigidArea(new Dimension(0, 25)));
add(perso);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
Object o = e.getSource();
if(o==map){fireChangePanel(1);}
if(o==quete){fireChangePanel(2);}
if(o==invent){fireChangePanel(3);}
if(o==perso){}
}
public void removeListener(MonListenerPerso list) {
monListenerPersoList.remove(list);
}
public void removeAllListeners() {
monListenerPersoList.clear();
}
public void addMonListenerPerso(MonListenerPerso list) {
if (!monListenerPersoList.contains(list)){
monListenerPersoList.add(list);
}
}
private void fireChangePanel(int panelNumber) {
for (int i=0; i<monListenerPersoList.size(); i++){ ((MonListenerPerso)monListenerPersoList.get(i)).updateRightPanel(panelNumber);
}
}
} |