当前位置: 技术问答>java相关
还是关于多窗口的问题?
来源: 互联网 发布时间:2015-02-02
本文导语: 在frame1上有一个按钮 点击这个按钮产生一个frame2的窗口, 但现在我一点击frame2窗口右上角的叉 frame1和frame2都关闭了,这是怎么回事 我只想关闭一个阿 | import java.awt.*; import java.awt.event.*; public class qw e...
在frame1上有一个按钮
点击这个按钮产生一个frame2的窗口,
但现在我一点击frame2窗口右上角的叉
frame1和frame2都关闭了,这是怎么回事
我只想关闭一个阿
点击这个按钮产生一个frame2的窗口,
但现在我一点击frame2窗口右上角的叉
frame1和frame2都关闭了,这是怎么回事
我只想关闭一个阿
|
import java.awt.*;
import java.awt.event.*;
public class qw extends Frame
{
Button b2;
public qw()
{
setLayout(new FlowLayout());
b2 = new Button("NEW");
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
f1 q = new f1();
q.show();
b2.setEnabled(false);
}
});
add(b2);
this.addWindowListener (new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}
});
}
public static void main(String args[])
{
System.out.println("Starting App");
qw f = new qw();
f.setSize(100,100);
f.show();
}
}
class f1 extends Frame
{
static f1 f;
Button b2;
public f1()
{
setLayout(new FlowLayout());
f = this;
setSize(200,200);
b2 = new Button("NEW");
add(b2);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}
});
}
}
class f2 extends Frame
{
Button b2;
public f2(final f1 f)
{
setSize(200,200);
setLayout(new FlowLayout());
b2 = new Button("close f1");
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
f.hide();
f.dispose();
b2.setEnabled(false);
}
});
add(b2);
}
public static void main(String args[])
{
System.out.println("Starting App");
qw f = new qw();
f.setSize(100,100);
f.show();
}
}
import java.awt.event.*;
public class qw extends Frame
{
Button b2;
public qw()
{
setLayout(new FlowLayout());
b2 = new Button("NEW");
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
f1 q = new f1();
q.show();
b2.setEnabled(false);
}
});
add(b2);
this.addWindowListener (new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}
});
}
public static void main(String args[])
{
System.out.println("Starting App");
qw f = new qw();
f.setSize(100,100);
f.show();
}
}
class f1 extends Frame
{
static f1 f;
Button b2;
public f1()
{
setLayout(new FlowLayout());
f = this;
setSize(200,200);
b2 = new Button("NEW");
add(b2);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}
});
}
}
class f2 extends Frame
{
Button b2;
public f2(final f1 f)
{
setSize(200,200);
setLayout(new FlowLayout());
b2 = new Button("close f1");
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
f.hide();
f.dispose();
b2.setEnabled(false);
}
});
add(b2);
}
public static void main(String args[])
{
System.out.println("Starting App");
qw f = new qw();
f.setSize(100,100);
f.show();
}
}