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
| public class FenetreDessin extends JFrame implements ActionListener {
public Fenetre() {
super("yooooo");
JMenuBar barre = new JMenuBar();
this.setJMenuBar(barre);
JMenu mFichier = new JMenu("Menu");
barre.add(mFichier);
JMenuItem mIOuvrir = new JMenuItem("nouveau");
mIOuvrir.addActionListener(this);
mFichier.add(mIOuvrir);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
String s = e.getActionCommand();
if (s.equals("nouveau")) {
int taille = Integer.parseInt(JOptionPane.showInputDialog(null, "Taille :"));
// Creation des composants
JTextField tTypegrille = new JTextField(20);
JTextField tJoueur = new JTextField(20);
JPanel p1 = new JPanel(new FlowLayout());
JPanel p2 = new JPanel(new FlowLayout());
p1.setMaximumSize(new Dimension(400, 30));
p2.setMaximumSize(new Dimension(400, 30));
p1.add(tTypegrille);
p2.add(tJoueur);
PanelDessin p = new p(taille);
psetPreferredSize(new Dimension(taille, taille));
p.setMaximumSize(new Dimension(taille, taille));
p.setBackground(Color.BLUE);
p.addMouseListener();
JPanel pan = new JPanel();
pan.setLayout(new BoxLayout(pan, BoxLayout.Y_AXIS));
pan.removeAll();
pan.updateUI();
pan.add(p1);
pan.add(p);
pan.add(p2);
this.add(pan);
this.pack();
pan.setVisible(true);
}
}
public static void main(String[] args) {
FenetreDessin fd = new FenetreDessin();
fd.setBounds(50, 50, 500, 500);
}
} |