要让子窗口始终显示在主窗口上面只要将主窗口作为子窗口的一个参数,保证主窗口始终在子窗口之前创建就可以了,但是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;
}
怎样在Java Applet中实现子窗口始终显示在主窗口上面
最新推荐文章于 2022-01-22 10:59:19 发布