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
|
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;
import javax.swing.JTextField;
public class testFrame extends JFrame{
public testFrame(){
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
getContentPane().setLayout(new FlowLayout());
getContentPane().add(new JTextField(15));
JButton newFrameButton = new JButton("New Frame");
newFrameButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
new SecondFrame().setVisible(true);
}
});
getContentPane().add(newFrameButton);
pack();
}
private class SecondFrame extends JFrame{
public SecondFrame(){
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
getContentPane().setLayout(new FlowLayout());
getContentPane().add(new JTextField(15));
JButton dialogButton = new JButton("DIALOG");
dialogButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
showDialog();
}
});
getContentPane().add(dialogButton);
pack();
}
public void showDialog(){
System.out.println("AVANT DIALOG");
final MyDialog myDialog = new MyDialog(this);
myDialog.show();
while(myDialog.isVisible()){
}
System.out.println("APRES DIALOG");
}
}
private class MyDialog extends JDialog{
private JFrame parentFrame;
public MyDialog(JFrame parent){
super(parent);
this.parentFrame= parent;
parentFrame.setEnabled(false);
getContentPane().setLayout(new FlowLayout());
JButton closeButton = new JButton("CLOSE");
getContentPane().add(closeButton);
closeButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
hide();
parentFrame.setEnabled(true);
}
});
pack();
}
}
public static void main(String[] args){
new testFrame().setVisible(true);
}
} |
Partager