Java swing 两个窗口关闭问题
我在做一个考试系统,有两个JFrame 一个是登陆窗体 LoginFrame , 一个是选题窗体 ChoiceFile ,在主程序里运行 LoginFrame ,我想在登录成功以后转到 ChoiceFile 窗体,同时关闭 LoginFrame 窗体。
现在我已经可以转到转到 ChoiceFile 窗体了,可是怎么关闭 LoginFrame 窗体呢?还请高手指点一下
可以试试这个,LoginFrame.dispose();//可以将LoginFrame从内存中释放掉
可以用LoginFrame.Hide() or LoginFrame.setVisible(false),将登陆窗口隐藏起来,反正占不到多少内存!
忘记说了,你可以在ChoiceFile窗体new出来之前或者调用它的setVisable(true)之后,立刻调用上面的那个方法
现写的,参考下
Java code:
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);
}
}
{{----}
相关问答:
不知道是什么原因,我该如何处理,请大虾们指教了,小弟在此谢过。。。。
错误信息如下:
The program being debugged was signaled while in a function called from GDB.
GDB has restored the context t ......
现在遇到这样一个问题:
在java 中编写swing程序, 添加按钮jbServerStart,目的是当点击jbServerStart时,程序会自动创建两个与其他终端通信的对象,代码如下:
private Container createButtonPane ......
Java是不是不可以继承父类构造方法?
我们老师给我写的这个我不是很明白。
1、子类继承父类所有父类的变量和方法,但不继承父类的构造方法,在子类的构造方法可以使用语句super(参数列表)调用父类的构 ......
如何将ArrayList.get()返回的objet转换成其他类型?或者我如何生成一个以float类型为基础的arraylist类型?或者我如何把arraylist.get()得到的值和float类型作比较?
如需要阅读该回复,请登录或注册CSDN!
......