关于对话框的问题

sixdayboy 2004-05-06 05:52:34
import java.awt.*;
import java.awt.event.*;

public class WWWW extends Frame implements ActionListener
{
Button btn=new Button("提示");
Panel p=new Panel();

WWWW()
{
super("Windows");
setSize(350,200);
setVisible(true);
add(p);
p.add(btn);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
show();
}

public static void main(String[] args)
{
new WWWW();
}

public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btn)
{
MyDialog dlg=new MyDialog(this,true);
dlg.show();
}
}

class MyDialog extends Dialog
{
Label label=new Label();

MyDialog(WWWW parent,boolean modal)
{
super(parent,modal);
setSize(260,140);
setResizable(false);
setLayout(null);
add(label);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
label.setText("你好");
}
}
}

为什么对话框出不来呢
...全文
64 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
dongdong715 2004-05-06
  • 打赏
  • 举报
回复
大胃不错哦,,他应该是没有在编译器运行的,我有要。
btn.addActionListener(this);//注册事件。
label.setBounds(100,60,40,30);//设置LABEL的显示位置。
dongdong715 2004-05-06
  • 打赏
  • 举报
回复
import java.awt.*;
import java.awt.event.*;

public class WWWW extends Frame implements ActionListener
{
Button btn=new Button("提示");
Panel p=new Panel();

WWWW()
{
super("Windows");
setSize(350,200);
btn.addActionListener(this);//注册事件。
setVisible(true);
add(p);
p.add(btn);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
show();
}

public static void main(String[] args)
{
new WWWW();
}

public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btn)
{
MyDialog dlg=new MyDialog(this,true);
dlg.show();
}
}

class MyDialog extends Dialog
{
Label label=new Label();

MyDialog(WWWW parent,boolean modal)
{
super(parent,modal);
setSize(260,140);

setResizable(false);
label.setText("你好");
setLayout(null);
label.setBounds(100,60,40,30);//设置LABEL的显示位置。
add(label);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});

}
}
}

swiminthesea 2004-05-06
  • 打赏
  • 举报
回复
嗯,嗯,大胃真厉害 ^_^
sean_gao 2004-05-06
  • 打赏
  • 举报
回复
btn.addActionListener(this);
explorman 2004-05-06
  • 打赏
  • 举报
回复
不知道,看不出错在哪了
(不过,建议你用swing设计界面,比awt好)

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧