2008-12-17 132 views
8

我有一个java小程序是嵌入在HTML使用object-comment-embed方法。我想在调整浏览器窗口大小时调整applet的大小。我在互联网上找到了解决方案,但它们都是基于已弃用的applet标签工作。如何在浏览器调整大小时调整java applet的大小?

此外,在FireBug中的embed元素上尝试setSize()调用时,它将调整applet的内容大小,但不调整applet视口的大小。也就是说,显示给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> 
+0

您的调整大小函数被调用? (例如,到目前为止,错误在哪里?) – scunliffe 2008-12-17 17:06:02

回答

4

尝试更换这些线路:

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

有:

document.getElementById('MyApplet1').style.height = applet_height + "px"; 
document.getElementById('MyApplet1').style.width = applet_width + "px"; 

document.getElementById('MyApplet2').style.height = applet_height + "px"; 
document.getElementById('MyApplet2').style.width = applet_width + "px"; 
+0

我的投票是针对这种方法的。我基本上做了同样的事情来调整ActiveX控件的大小。对于一个Applet它应该是一样的。 – CodingWithSpike 2008-12-19 21:59:46

1

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

<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> 
相关问题