import java.awt.*;
import java.awt.event.*;public class qw extends Frame
{
   Button b2; public qw()
{
   setLayout(new FlowLayout());
   
   b2 = new Button("NEW");
   b2.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e){ 
         f1 q = new f1();
         q.show();
         b2.setEnabled(false);
      } 
   });
   add(b2);
this.addWindowListener (new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}
});
}

public static void main(String args[])
{
System.out.println("Starting App");
qw f = new qw();
f.setSize(100,100);
f.show();
}
}class f1 extends Frame
{
   static f1 f;
   Button b2; public f1()
{
   setLayout(new FlowLayout());
   f = this;
   setSize(200,200);
   b2 = new Button("NEW");
  
   add(b2);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}
});
}

}class f2 extends Frame
{
   
   Button b2;
   
public f2(final f1 f)
{
   setSize(200,200);
   setLayout(new FlowLayout());
   
   b2 = new Button("close f1");
   b2.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e){ 
         f.hide();
         f.dispose();
         b2.setEnabled(false);
      } 
   }); 
          
   add(b2);

}

public static void main(String args[])
{
System.out.println("Starting App");
qw f = new qw();
f.setSize(100,100);
f.show();
}
}

解决方案 »

  1.   

    这个是对的import java.awt.*;
    import java.awt.event.*;public class qw extends Frame
    {
       Button b2; public qw()
    {
       setLayout(new FlowLayout());
       
       b2 = new Button("NEW");
       b2.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent e){ 
             f1 q = new f1();
             q.show();
             b2.setEnabled(false);
          } 
       });
       add(b2);
    this.addWindowListener (new WindowAdapter(){
    public void windowClosing(WindowEvent e){
    dispose();
    System.exit(0);
    }
    });
    }

    public static void main(String args[])
    {
    System.out.println("Starting App");
    qw f = new qw();
    f.setSize(100,100);
    f.show();
    }
    }class f1 extends Frame
    {
       static f1 f;
       Button b2; public f1()
    {
       setLayout(new FlowLayout());
       setSize(200,200);
       f = this;
       b2 = new Button("NEW");
       b2.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent e){ 
             f2 q = new f2(f);
             q.show();
             b2.setEnabled(false);
          } 
       });
       add(b2);
    this.addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent e){
    dispose();

    }
    });
    }

    }class f2 extends Frame
    {
       
       Button b2;
       
    public f2(final f1 f)
    {
       setSize(200,200);
       setLayout(new FlowLayout());
       
       b2 = new Button("close f1");
       b2.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent e){ 
             f.hide();
             f.dispose();
             b2.setEnabled(false);
          } 
       }); 
              
       add(b2);
    this.addWindowListener (new WindowAdapter(){
    public void windowClosing(WindowEvent e){
    dispose();

    }
    });
    }

    public static void main(String args[])
    {
    System.out.println("Starting App");
    qw f = new qw();
    f.setSize(100,100);
    f.show();
    }
    }
      

  2.   

    在你的frame2的windowClosing()事件中重写为:frame2.hide()或frame2.dispose()