就是一个界面中的cancel按钮,我想通过它关闭窗体。希望大家帮个忙

解决方案 »

  1.   

    给这个cancel按钮注册一个事件
    JButton cancelBtn = new JButton("Cancel");
    cancelBtn.addActionListener(this);
    public void actionPerformed(){
        this.close();
    }
      

  2.   

    JButton cancelBtn = new JButton("Cancel");
    cancelBtn.addActionListener(new ActionListener()
    {
    public void actionPerformed(){
       window.dispose();
    }
    });
    window 是你要关闭的窗口的引用