我在做一个考试系统,有两个JFrame 一个是登陆窗体 LoginFrame , 一个是选题窗体 ChoiceFile ,在主程序里运行 LoginFrame ,我想在登录成功以后转到 ChoiceFile 窗体,同时关闭 LoginFrame 窗体。
现在我已经可以转到转到 ChoiceFile 窗体了,可是怎么关闭 LoginFrame 窗体呢?还请高手指点一下

解决方案 »

  1.   

    可以试试这个,LoginFrame.dispose();//可以将LoginFrame从内存中释放掉
      

  2.   

    可以用LoginFrame.Hide() or LoginFrame.setVisible(false),将登陆窗口隐藏起来,反正占不到多少内存!
      

  3.   

    忘记说了,你可以在ChoiceFile窗体new出来之前或者调用它的setVisable(true)之后,立刻调用上面的那个方法
      

  4.   

    现写的,参考下public class TestFrame extends JFrame implements ActionListener{
    private JButton jbutton = new JButton("打开选题窗口");
    private ChoiceFrame choiceFrame;
    public TestFrame(){
    jbutton.addActionListener(this);
    this.add(jbutton);
    this.setBounds(200,200,500,400);
    this.setVisible(true);
    }
    public static void main(String[] args){
    new TestFrame();
    }

    public void actionPerformed(ActionEvent e){
    choiceFrame = new ChoiceFrame();
    this.dispose();
    }
    }class ChoiceFrame extends JFrame {
    public ChoiceFrame(){
    this.setTitle("选题");
    this.setBounds(400,400,400,400);
    this.setVisible(true);
    }
    }
      

  5.   

     //调用主界面,关闭当前界面
      new FrameStudent();
      this.dispose();
      this代表你当前的界面 
    FrameStudent代表你要打开的界面 
    既然你可以打开 那么你直接在打开你新的界面后 用当前对象调用 dispose方法关掉即可