从Frame中弹出一个Dialog,点右上角红叉关闭Dialog时Frame也关闭,怎样让能点右上角红叉时返回Frame
从Frame中弹出一个Dialog,点右上角红叉关闭Dialog时Frame也关闭,
怎样让能点右上角红叉时返回Frame
参考代码(已调试过):
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class enc2_2 extends WindowAdapter implements ActionListener
{
private Frame f;
private TextField tf1,tf2;
private Button b1,b2;
public static void main (String[] args){
enc2_2 a=new enc2_2();
a.go();
}
public void go(){
f=new Frame("enc2");
f.addWindowListener(this);
f.setLayout(new FlowLayout());
tf1=new TextField("",30);
tf2=new TextField("code",6);
b1=new Button("ok");
b2=new Button("exit");
b1.addActionListener(this);
b2.addActionListener(this);
f.add(tf1);
f.add(tf2);
f.add(b1);
f.add(b2);
f.setSize(500,500);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("ok"))
{
if(!tf2.getText().equals("abc"))
{
InfoDialog ifd=new InfoDialog(f,true);
ifd.l1.setText("密码错误");
ifd.addWindowListener(this);
ifd.show();
}
}
else if(e.getActionCommand().equals("exit"))System.exit(0);
}
public void windowClosing(WindowEvent we){System.exit(0);}
}
class InfoDialog extends Dialog implements ActionListener{
Label l1=new Label("完成");
Button bb=new Button("返回");
InfoDialog(Frame fr,boolean m){
super(fr,m);
add(l1);
bb.addActionListener(this);
add("South",bb);
setSize(300,100);
}
public void actionPerformed(ActionEvent e){
dispose();
}
}