java窗体上的按钮事件弹出另一个窗体怎么令前1个窗体关闭

前1个窗体关闭只显示后来显示的怎么实现
public class jiemianshijian1 implements ActionListener{

public void actionPerformed(ActionEvent e) {
if(e.getSource()==b5){
new jiemian2().setVisible(true);
}
if(e.getSource()==b6){

}
if(e.getSource()==b7){

}
if(e.getSource()==b8){

}
if(e.getSource()==b9){
System.exit(0);
}

}

}
代码太多了粘不上去就是2个窗体,第一个窗体上的按钮事件弹出的第2个现在想只显示2,第一个关闭

第1个回答  2010-05-15
楼主把代码贴出来,我帮你看看
-------------------------------------------------
楼主看看下面的代码符合你要求不,不符合的话给我发百度消息:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TestWindow implements ActionListener {
JFrame frame1,frame2;
JButton btn;
public static void main(String[] args) {
new TestWindow("first");
}
public TestWindow(String s) {
btn=new JButton("开启第二个窗口");
btn.addActionListener(this);
frame1=new JFrame();
frame2=new JFrame();
create1(s);
}
public void create1(String s) {
frame1.setTitle(s);
frame1.setSize(100,100);
frame1.getContentPane().add(btn);
frame1.setVisible(true);

}
public void create2() {
frame2.setTitle("second");
frame2.setSize(100,100);
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame2.setVisible(true);
frame1.dispose();
}
public void actionPerformed(ActionEvent e) {
create2();
}
}
第2个回答  2010-05-15
在事件监听方法中写上:
System.exit(0);//关闭当前窗口
new AnotherFrame();//打开另外一个窗口 AnotherFrame是另外一个窗口类
第3个回答  2010-05-15
if(e.getSource()==b5){
jf1.setVisible(false); //把第一个隐藏
new jiemian2().setVisible(true);
}本回答被网友采纳
第4个回答  2010-05-15
在点击按钮时,您需要获得前一个窗体的对象,让之隐藏应该可以了,
相似回答