java 怎么用setVisible(false);方法隐藏其他窗口
this.addWindowListener(newjava.awt.event.WindowAdapter(){publicvoidwindowOpened(java....
this.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent e) {
denlu b=new denlu();
b.setVisible(false);
我写了这条语句希望本窗口被打开时隐藏名为“denlu”的窗口,没有成功,不知为什么。 展开
public void windowOpened(java.awt.event.WindowEvent e) {
denlu b=new denlu();
b.setVisible(false);
我写了这条语句希望本窗口被打开时隐藏名为“denlu”的窗口,没有成功,不知为什么。 展开
2个回答
展开全部
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");
}
}
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");
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询