class ScenePaint extends Frame
 { 
    ......
    public ScenePaint(){
          addWindowListener (new WindowAdapter() //使主窗口能关闭
     {public void windowClosing(WindowEvent e)
       {setVisible (false);
        }}
    private Panel makeButtons()
     {
        Panel p=new Panel();
        p.add(new ButtonAdapter("Quit")
           {
   public void pressed(){??????}
            }
     }
 }我想点击“Quit”按钮,将主窗口关掉,该怎么写。谢谢

解决方案 »

  1.   

    System.exit(0);addWindowListener (new WindowAdapter() //使主窗口能关闭
         {public void windowClosing(WindowEvent e)
           {setVisible (false);
            }}
    这个关闭有问题,就算你用System.exit(0);这样,而且你只是设置成不可见,用
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);可以在点叉的时候关闭窗体
      

  2.   

    ScenePaint.this.setVisible(false);
    ScenePaint.this.dispose();