第1个回答 推荐于2018-02-27
this.setVisible(false);//隐藏当前窗体,如果当前窗体Frame的名为f则写成:f.setVisible(false);
new JFrameTest();//要新出来的窗体
如点击按钮出现一新的窗口,3秒后消失。
import java.awt.*;
import java.awt.event.*;
public class HideWind extends Frame {
Button b = new Button("window");
double heigth, weigth;
double x, y;
TextField tf1 = new TextField(null, 10);
TextField tf2 = new TextField(null, 10);
public HideWind(String name) {
super(name);
setLayout(new FlowLayout(FlowLayout.LEFT));
add(tf1);
add(tf2);
add(b);
pack();
setVisible(true);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
b.addActionListener(new ButtonListener());
}
class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
HideWind w = new HideWind("bbbbbbbbbbbb");
try {
Thread.sleep(3000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
w.setVisible(false);
}
}
public static void main(String[] args) {
new HideWind("windows1");
}
}本回答被提问者和网友采纳