调整浏览器大小时如何调整java小程序的大小?

调整浏览器大小时如何调整java小程序的大小?,java,javascript,applet,resize,Java,Javascript,Applet,Resize,我有一个java小程序,它使用objectcommentembed方法嵌入到html中。每当调整浏览器窗口的大小时,我都想调整小程序的大小。我已经在互联网上找到了解决方案,但它们都是基于不推荐的applet标签工作的 另外,在FireBug中尝试调用我的embed元素时,它会调整小程序的内容,但不会调整小程序视口的大小。也就是说,交给java的显示区域不会改变 当前代码如下所示: <object id='MyApplet1' width='300' height='200'

我有一个java小程序,它使用
objectcommentembed
方法嵌入到html中。每当调整浏览器窗口的大小时,我都想调整小程序的大小。我已经在互联网上找到了解决方案,但它们都是基于不推荐的
applet
标签工作的

另外,在FireBug中尝试调用我的
embed
元素时,它会调整小程序的内容,但不会调整小程序视口的大小。也就是说,交给java的显示区域不会改变

当前代码如下所示:

<object
    id='MyApplet1'
    width='300' height='200'
    classid='clsid:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
    codebase='http://java.sun.com/update/1.6.0/jinstall-6-windows-i586.cab#Version=1,6,0,0'>
    <param name='type' value='application/x-java-applet;version=1.6'>
    <param name='scriptable' value='false'>
    <param name='codebase' value='foo'>
    <param name='code' value='bar'>
    <param name='archive' value='baz'>
    <param name='arg1' value='A'>
    <param name='arg2' value='B'>
    <comment>
        <embed
            id='MyApplet2'
            width='300' height='200'
            pluginspage='http://java.sun.com/products/plugin/index.html#download'
            type='application/x-java-applet;version=1.6'
            scriptable='false'
            codebase='foo'
            code='bar'
            archive='baz'
            arg1='A'
            arg2='B'>
            <noembed>
            </noembed>
        </embed>
    </comment>
</object>
<script type="text/javascript"> 
function resize() {
  min_width = 300;
  min_height = 200;
  frame_width = 0;
  frame_height = 0;
  if(parseInt(navigator.appVersion) > 3) {
    if(navigator.appName=='Netscape') {
      frame_width = window.innerWidth;
      frame_height = window.innerHeight;
    }
    if (navigator.appName.indexOf('Microsoft') != -1) {
      frame_width = document.body.offsetWidth;
      frame_height = document.body.offsetHeight;
    }
  }
  frame_width *= 0.78;
  frame_height *= 0.78;
  applet_width = frame_width > min_width ? frame_width : min_width;
  applet_height = frame_height > min_height ? frame_height : min_height;
  document.getElementById('MyApplet1').setSize(applet_width, applet_height);
  document.getElementById('MyApplet2').setSize(applet_width, applet_height);
}
window.onResize = resize;
window.onLoad = resize;
</script> 

函数resize(){
最小宽度=300;
最小高度=200;
帧宽度=0;
框架高度=0;
if(parseInt(navigator.appVersion)>3){
if(navigator.appName=='Netscape'){
框架宽度=窗内宽度;
框架高度=窗内高度;
}
if(navigator.appName.indexOf('Microsoft')!=-1){
框架宽度=document.body.offsetWidth;
框架高度=document.body.offsetHeight;
}
}
框架宽度*=0.78;
框架高度*=0.78;
小程序宽度=帧宽度>最小宽度?帧宽度:最小宽度;
小程序高度=帧高度>最小高度?帧高度:最小高度;
document.getElementById('MyApplet1').setSize(小程序宽度,小程序高度);
document.getElementById('MyApplet2').setSize(小程序宽度、小程序高度);
}
window.onResize=调整大小;
window.onLoad=调整大小;

尝试替换以下行:

document.getElementById('MyApplet1').setSize(applet_width, applet_height);
document.getElementById('MyApplet2').setSize(applet_width, applet_height);
与:


为什么不使用宽度和高度的百分比呢。我的小程序通常使用以下代码:

<applet codebase="http://localhost:89" archive="npaxet?version=0.0.1.28" code="main.NPaxet.class" width=100% height=90%>\
<PARAM NAME="thumbnailUrl" VALUE="http://localhost:89/thumbnail?seriesid=%s">
<PARAM NAME="dicomUrl" VALUE="http://localhost:89/dicom?imageid=%d">
<PARAM NAME="seriesCount" VALUE="11">
...
</applet>
\
...

是否调用了调整大小功能?(例如,到目前为止错误在哪里?)我赞成这种方法。我基本上也做了同样的事情来调整ActiveX控件的大小。对于小程序来说应该是一样的。这是有效的!我也在做同样的事情,使用setSize()。正在调用它,但小程序没有调整大小。谢谢
<applet codebase="http://localhost:89" archive="npaxet?version=0.0.1.28" code="main.NPaxet.class" width=100% height=90%>\
<PARAM NAME="thumbnailUrl" VALUE="http://localhost:89/thumbnail?seriesid=%s">
<PARAM NAME="dicomUrl" VALUE="http://localhost:89/dicom?imageid=%d">
<PARAM NAME="seriesCount" VALUE="11">
...
</applet>