/** StdDialog.java boîte de dialogue (dérive de JDialog) avec des boutons en bas. */ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; public class StdDialog extends JDialog { JPanel panneau = new JPanel(); JPanel pan_cent = new JPanel(); JButton b_ok = new JButton(); JButton b_annul = new JButton(); Border border1; JPanel pan_bas = new JPanel(); GridBagLayout geometre = new GridBagLayout(); GridLayout geom_bas = new GridLayout(); public StdDialog(Frame frame, String title, boolean modal) { super(frame, title, modal); try { dessineFen(); } catch (Exception e) { e.printStackTrace(); } pack(); } public StdDialog(Frame frame, String title) { super(frame, title, false); } public StdDialog(Frame frame) { super(frame, "", false); } private void dessineFen() throws Exception { // Panneau // Panneau du bas // Ses deux boutons b_ok.setText("OK"); b_annul.setText("Annuler"); border1 = BorderFactory.createRaisedBevelBorder(); pan_bas.setLayout(geom_bas); geom_bas.setHgap(4); pan_bas.add(b_ok, null); pan_bas.add(b_annul, null); // Panneau central pan_cent.setBackground(Color.white); pan_cent.setBorder(border1); panneau.setLayout(geometre); panneau.add(pan_cent, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(4, 8, 4, 8), 0, 0)); getContentPane().add(panneau); // Associations avec capteurs this.addWindowListener(new StDlg1_adaptation(this)); b_ok.addActionListener(new StDlg1_b_ok_adaptation(this)); b_annul.addActionListener(new StDlg1_b_annul_adaptation(this)); } // OK void b_ok_reflexe(ActionEvent e) { dispose(); } // Annuler void b_annul_reflexe(ActionEvent e) { dispose(); } void this_windowClosing(WindowEvent e) { dispose(); } } // fin class StdDialog class StDlg1_b_ok_adaptation implements ActionListener { StdDialog fen; StDlg1_b_ok_adaptation(StdDialog f) { this.fen = f; } public void actionPerformed(ActionEvent e) { fen.b_ok_reflexe(e); } } class StDlg1_b_annul_adaptation implements ActionListener { StdDialog fen; StDlg1_b_annul_adaptation(StdDialog f) { this.fen = f; } public void actionPerformed(ActionEvent e) { fen.b_annul_reflexe(e); } } class StDlg1_this_adaptation extends WindowAdapter { StdDialog fen; StDlg1_this_adaptation(StdDialog f) { this.f = fen; } public void windowClosing(WindowEvent e) { fen.this_windowClosing(e); } } // fin StdDialog