首页 > 学院 > 开发设计 > 正文

在Java applet中如何实现一个模式对话框?

2019-11-18 15:21:13
字体:
来源:转载
供稿:网友

  在java applet中实现模式对话框的要害就是在创建一个对话框的时候 要为该对话框指定一个正确的父窗口.因为Applet是Panel类的子类,不 可以作为对话框的父窗口,所以首先要获得applet所在的窗口,作为模式 对话框的父窗口. 样例代码如下:
.....
Dialog d = new Dialog( getParentWindow(comp),title);
// comp为applet上的任意一个组件
....
public void getParentWindow(Component compOnApplet,String title){
Container c = compOnApplet.getParent();
while (c != null) {
if (c instanceof Frame)
return (Frame) c;
c = c.getParent();
}
return null;
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表