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重启呢? ......
我想做够购物车用session 但是不知道怎么获取购买数量 谁有具体的代码吗 希望能割舍
下面是购物车的核心代码
有了这个 就应该能够做出来吧
Java code:
public void doPost(HttpServletRequest reque ......
查API,看到FeatrueFactory有这个方法
public Feature createPolyLine(double[][] thePoints,
R ......
我在eclipse中写了一个播放音乐的类,并把音乐文件和类文件放在了一起,结果运行时,出现错误,说是音乐文件那个是空的,但是在jcreator用同样的方法结果是可以运行的,请求高说指教,告诉为什么?急
你若是在Windo ......