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
|
public void actionPerformed(ActionEvent ae){
//Création de la fenetre
connex = new JFrame("Connexion");
connex.setSize(600,150);
connex.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
deconnect.setEnabled(true);
connect.setEnabled(false);
//Création de l'interface
//Positionnement
GridBagLayout layout = new GridBagLayout();
// getContentPane().setLayout(layout);
getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(layout);
GridBagConstraints contraintes = new GridBagConstraints();
//Création des éléments graphiques
mode = new JLabel("Mode de connexion");
group = new ButtonGroup();
client = new JRadioButton("Client", true);
client.setActionCommand("client");
serveur = new JRadioButton("Serveur", false);
serveur.setActionCommand("serveur");
group.add(client);
group.add(serveur);
label = new JLabel("IP du serveur : ");
ip = new JTextField(20);
ok = new JButton("OK");
annuler = new JButton("Annuler");
//Action des éléments graphiques
annuler.addActionListener(new fermerFenetre());
ok.addActionListener(new choixMode());
//Position des composants dans l'interface
contraintes.gridwidth = 4;
contraintes.gridx = 1;
contraintes.gridy = 1;
panel.add(mode,contraintes);
// layout.setConstraints(mode,contraintes);
contraintes.gridwidth = 1;
contraintes.gridy=2;
contraintes.gridx=1;
panel.add(client,contraintes);
// layout.setConstraints(client,contraintes);
contraintes.gridx = 3;
panel.add(label,contraintes);
// layout.setConstraints(label,contraintes);
contraintes.gridx= 4;
panel.add(ip,contraintes);
// layout.setConstraints(ip,contraintes);
contraintes.gridx = 1;
contraintes.gridy=3;
panel.add(serveur,contraintes);
// layout.setConstraints(serveur,contraintes);
contraintes.gridy = 4;
panel.add(ok,contraintes);
// layout.setConstraints(ok,contraintes);
contraintes.gridx = 4;
panel.add(annuler,contraintes);
// layout.setConstraints(annuler,contraintes);
//Ajout des composants
connex.getContentPane().add(panel, BorderLayout.CENTER);
// getContentPane().add(mode);
// getContentPane().add(client);
// getContentPane().add(label);
// getContentPane().add(ip);
// getContentPane().add(serveur);
// getContentPane().add(ok);
// getContentPane().add(annuler);
// connex.setContentPane(pane);
//Affichage
connex.setVisible(true);
} |
Partager