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
| package JDialog;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
public class DeuxJDialog2 {
private JFrame frame = new JFrame();
JButton button = new JButton("go");
JdialogParent jdp;
public DeuxJDialog2() {
frame.setSize(300, 300);
frame.setVisible(true);
frame.getContentPane().setLayout(new FlowLayout());
frame.add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jdp = new JdialogParent(frame);
}
});
}
@SuppressWarnings("serial")
class JdialogEnfant extends JDialog {
public JdialogEnfant(JdialogParent jdp) {
super(jdp);
setTitle("Enfant");
setSize(100, 100);
setLocationRelativeTo(null);
setModal(true);
setVisible(true);
}
}
@SuppressWarnings("serial")
class JdialogParent extends JDialog {
JButton button2 = new JButton("go");
public JdialogParent(JFrame parent) {
super(parent);
setSize(200, 200);
setTitle("Parent");
setLocationRelativeTo(null);
setModal(true);
this.getContentPane().setLayout(new FlowLayout());
this.add(button2);
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new JdialogEnfant(JdialogParent.this);
}
});
setVisible(true);
}
}
public static void main(String[] args) {
new DeuxJDialog2();
}
} |