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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
| import java.awt.event.*;
import java.awt.event.ActionListener;
import java.awt.*;
import java.util.Vector;
import javax.swing.*;
public class PrincipalWindow extends JFrame implements ActionListener {
private JMenuBar _menubar ;
private JMenu _menuPrincipal;
private JMenu _menuHelp;
private JMenuItem _menuNewGame;
private JMenuItem _menuControl;
private JMenuItem _Quit;
private JMenuItem _helpGame;
private JMenuItem _helpProg;
private JMenuItem _helpWhoBuildGame;
private JFrame JF1;
private GridLayout _lm;
private JTextArea _textArea;
private JPanel _pane;
private int _nbOfLines;
private int _nbOfColumns;
private String _J1Name;
private String _J2Name;
public PrincipalWindow(){ //Constructeur
_menubar = new JMenuBar();
_menuPrincipal = new JMenu("menu principal");
_menuHelp = new JMenu("Aide");
_menuNewGame = new JMenuItem("Nouveau Jeu");
_menuPrincipal.add(_menuNewGame);
_menuNewGame.addActionListener(this);
_menuControl = new JMenuItem("Boite de commande");
_menuPrincipal.add(_menuControl);
_menuControl.addActionListener(this);
_Quit = new JMenuItem("Quitter");
_menuPrincipal.add(_Quit);
_Quit.addActionListener(this);
_helpGame = new JMenuItem("Regle du jeu");
_menuHelp.add(_helpGame);
_helpGame.addActionListener(this);
_helpProg = new JMenuItem("Comment marche le programme ?");
_menuHelp.add(_helpProg);
_helpProg.addActionListener(this);
_helpWhoBuildGame = new JMenuItem("qui à créer le jeu ?");
_menuHelp.add(_helpWhoBuildGame);
_helpWhoBuildGame.addActionListener(this);
_menubar.add(_menuPrincipal);
_menubar.add(_menuHelp);
this.setJMenuBar(_menubar);
_pane = new JPanel(); //Definition du panel et placement dans la fenetre
this.setContentPane(_pane);
}
public void actionPerformed(ActionEvent evt){
//Traitement différent suivant l'émetteur des évenements
if(evt.getSource()==_helpGame){
System.out.println("cas menuAide");
HelpWindow hw1 = new HelpWindow();
hw1.pack();
hw1.setVisible(true);
}
if(evt.getSource()==_Quit){
dispose();
}
if(evt.getSource()==_menuNewGame){
NewGameWindow ngw = new NewGameWindow(JF1,true);
ngw.pack();
ngw.setVisible(true);
_nbOfLines = ngw.getSizeLine();
System.out.println(_nbOfLines+"at1");
_nbOfColumns = ngw.getSizeColumn();
System.out.println(_nbOfColumns+"at1");
_J1Name= ngw.getNameJ1();
_J2Name=ngw.getNameJ2();
}
if(evt.getSource()== _menuControl){
}
}
public int getSizeLines(){
return _nbOfLines;
}
public void setSizeLines(int a){
_nbOfLines = a;
}
public int getSizeColumns(){
return _nbOfColumns;
}
public void setSizeColumns(int a){
_nbOfColumns = a;
}
public String getNameJ1(){
return _J1Name;
}
public String getNameJ2(){
return _J2Name;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
PrincipalWindow F1 = new PrincipalWindow();
WindowListener Fl = new WindowAdapter(){
public void windowClosing(WindowEvent e){ System.exit(0); }
};
F1.pack();
F1.setVisible(true);
System.out.println("fin");
System.out.println(F1.getSizeLines()+"fin");
System.out.println(F1.getSizeColumns()+"fin");
System.out.println(F1.getSizeLines()+"fin");
}
} |
Partager