JDialog,JOptionPane这些组件的弹出都需要一个父窗体;(虽然也可以传入null,但不想这样)
在appliction中,我可以用frame;
那么如果到了applet中,它的窗体我应该怎么得到呢?麻烦各位帮忙看看

解决方案 »

  1.   

    在applet中,应该可以用JApplet吧。 
      

  2.   


    JApplet它是继承panel的.它属于面板,不属于窗体;
      

  3.   


        /**
         * 获得组件依附的JFrame
         * @param comp
         * @return
         */
       private static Frame getParentFrame(Component comp){
            if(comp instanceof Frame){
                return(Frame)comp;
            }
            for(Component c = comp;c!=null;c = c.getParent()){
                if(c instanceof Frame){
                    return(Frame)c;
                }
            }
            return null;
        }