import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
public class MyJFrame extends JFrame{
JFrame MyOwner ;
public MyJFrame(JFrame owner,String title) {
super(title) ;
this.MyOwner=owner;
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
MyOwner.setEnabled(true);
}
});
}
public void show(){
super.show();
this.MyOwner.setEnabled(false);
}
private static void createAndShowGUI(){
JFrame frame = new
JFrame( "我是父frame ");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(50 , 50 , 480 , 320);
frame.setVisible(true);
MyJFrame mf = new MyJFrame(frame, "我是模态frame ");
mf.setBounds(50 , 50 , 240 , 180);
mf.show();
}
public static void main(String args[]) {
javax.swing.SwingUtilities.invokeLater(new Runnable(){
public void run(){
createAndShowGUI();
}
});
}
}