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 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
private JLabel leftLabel = new JLabel();
private JLabel rightLabel = new JLabel();
private JLabel 1Label = new JLabel("Info:");
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(leftLabel), new JScrollPane(rightLabel));
public MaFrame(){
super();
this.setTitle("");
this.setSize(1000,700);
this.setResizable(false);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setJMenuBar(this.creationJmenu());
this.setVisible(true);
splitPane.setRightComponent(joueur1Label);
add(splitPane);
}
private JMenuBar creationJmenu() {
//Création des Objets
JMenuBar jmb = new JMenuBar();
JMenu menu = new JMenu("Jeu");
JMenu edit = new JMenu("Editer");
JMenu taille = new JMenu("taille");
JMenuItem itemQuitter = new JMenuItem("Quitter");
JMenuItem itemPartie = new JMenuItem("CommencerPartie");
JMenuItem itemNormal = new JMenuItem("Normal");
JMenuItem itemPecran = new JMenuItem("Plein Ecran");
itemQuitter.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_J,InputEvent.CTRL_DOWN_MASK));
itemPecran.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P,InputEvent.CTRL_DOWN_MASK));
//Ajout des JMenuItem au JMenu
menu.add(itemPartie);
menu.add(itemQuitter);
taille.add(itemNormal);
taille.add(itemPecran);
edit.add(taille);
//Ajout des JMenu au JmenuBar
jmb.add(menu);
jmb.add(edit);
//Ajout des listener au JMenuItem
itemPartie.addActionListener(this);
itemQuitter.addActionListener(this);
itemNormal.addActionListener(this);
itemPecran.addActionListener(this);
return jmb;
}
public void actionPerformed(ActionEvent e) {
String action = e.getActionCommand();
if (action.equals("Normal")){
this.setSize(400, 400);
}else if(action.equals("Plein Ecran")){
this.setExtendedState(Frame.MAXIMIZED_BOTH);
}else if(action.equals("Quitter")){
System.exit(0);
}
else if(action.equals("CommencerPartie")){
//nouvelle fenetre qui s'ouvre
}
}
public static void main(String[] args){
MaFrame mframe = new MaFrame();
mframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mframe.setVisible(true);
}
} |
Partager