求大神指教为什么Dialog对话框不能显示出来
import java.awt.*;import java.awt.event.*;
public class TextDialog
{
public static void main(String args[])
{
Da df=new Da();
}
}
class Da extends Frame
{
TextField text1=new TextField("````",30);
Button btn1=new Button("隐藏");
Button btn2=new Button("测试按钮");
Da() //构造函数
{
super("对话框");
setLayout(new FlowLayout());
add(text1);
add(btn1);
add(btn2);
btn1.addActionListener(new KL());
btn2.addComponentListener(new Ha());
this.addWindowListener(new AS());
setSize(300,100);
setVisible(true);
}
class KL implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand()=="隐藏")
{
btn2.setVisible(false);
btn1.setLabel("显示");
}
else
{
btn2.setVisible(true);
btn1.setLabel("隐藏");
}
}
}
class Ha extends ComponentAdapter
{
public void componentHidden(ComponentEvent e)
{
text1.setText("测试按钮被隐藏");
}
public void componentShown(ComponentEvent e)
{
text1.setText("测试按钮被显示");
}
}
class AS extends WindowAdapter //
{
public void windowXlosing(WindowEvent e)
{
Frame f=(Frame)(e.getWindow());
ConfirmDlg confirm=new ConfirmDlg(f);
if(confirm.ans)
{
f.dispose();
System.exit(0);
}
}
}
}
class ConfirmDlg implements ActionListener
{
Dialog dlg;
Label message=new Label("是否关闭窗口");
Button btny=new Button(" 是 ");
Button btnn=new Button(" 否 ");
Panel b1=new Panel();
Panel b2=new Panel();
boolean ans;
ConfirmDlg(Frame own)
{
btny.addActionListener(this);
btnn.addActionListener(this);
dlg=new Dialog(own,"确认对话框",true);
b1.add(message);
b2.add(btny);
b2.add(btnn);
dlg.add(b1,BorderLayout.NORTH);
dlg.add(b2,BorderLayout.SOUTH);
dlg.setSize(200,100);
dlg.setVisible(true);
}
public void actionPerformed(ActionEvent e) //actionPerformed
{
dlg.dispose();
if(e.getActionCommand()=="是 ")
ans=true;
else
ans=false;
}
}