标题:求大神指教为什么Dialog对话框不能显示出来
只看楼主
阿里那个巴巴
Rank: 3Rank: 3
来 自:中山大学
等 级:论坛游侠
威 望:2
帖 子:55
专家分:153
注 册:2013-3-19
结帖率:100%
已结贴  问题点数:10 回复次数:1 
求大神指教为什么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;
    }
}
搜索更多相关主题的帖子: static void public import 对话框 
2013-04-07 22:36



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-403270-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.221422 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved