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

慕雪6442864
TA贡献1812条经验 获得超5个赞
在 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;
添加回答
举报
0/150
提交
取消