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);
}
}
{{----}
相关问答:
我目前在本地的linux上写了一个swing的界面,想通过这个界面来控制其它电脑的linux重启。
我知道用Runtime.getRuntime().exec("shutdown -r");可以控制本机Linux重启,但是怎么控制远程的linux重启呢? ......
我的开发的平台是Myeclipes6.0 + tomcat5.x + mysql
我所有的编码方式都是用的UTF-8
我只用了Strtus框架
在一个form中如下用的是post的提交方式:
<form class="form" action=&quo ......
工作地点:上海张江
学历要求:大本或以上
专业要求:计算机相关专业
英语:熟练(美国项目,英语工作环境,英语是必须)
简历投递:wendy_qian@163.com
MSN:wendydzmm@hotmail.com
......
现在遇到这样一个问题:
在java 中编写swing程序, 添加按钮jbServerStart,目的是当点击jbServerStart时,程序会自动创建两个与其他终端通信的对象,代码如下:
private Container createButtonPane ......
Java code:
import java.awt.*;
import java.awt.event.*;
public class TaskList extends Frame implements ActionListener
{
private Button b1 = new Button("确定");
private Button ......