2012-03-13 137 views
1

我是新来的,这可能是一个简单的修复。我目前正在使用JavaScript获取窗口高度和宽度,并且想要使用javascript变量设置applet的高度和宽度。JApplet根据javascript中的窗口宽度和高度设置HTML中的宽度和高度

这里是我的代码:

<html> 
<title>Applet</title> 
<head> 

<script type="text/javascript"> 
var winW = 630, winH = 460; 
if (document.body && document.body.offsetWidth) { 
winW = document.body.offsetWidth; 
winH = document.body.offsetHeight; 
} 
if (document.compatMode=='CSS1Compat' && 
    document.documentElement && 
    document.documentElement.offsetWidth) { 
winW = document.documentElement.offsetWidth; 
winH = document.documentElement.offsetHeight; 
} 
if (window.innerWidth && window.innerHeight) { 
winW = window.innerWidth; 
winH = window.innerHeight; 
} 
</script> 


</head> 
<body> 
<script type="text/javascript"> 
document.writeln('Window width = '+winW); 
document.writeln('Window height = '+winH); 
</script> 
<applet code="applet.class" 
     archive="applet7.jar, collections-generic-4.01.jar, colt-1.2.0.jar, jung-api-2.0.1, neo4j-kernel-1.6.M01.jar, blueprints-core-1.1.jar, jung-visualization-2.0.1.jar, jung-algorithms-2.0.1.jar, jung-3d-2.0.1.jar, jung-jai-samples-2.0.1.jar, jung-3d-demos-2.0.1.jar, jung-samples-2.0.1.jar, jung-io-2.0.1.jar, jung-graph-impl-2.0.1.jar, jung-jai-2.0.1.jar, blueprints-graph-sail-1.1.jar, blueprints-dex-graph-1.1.jar, blueprints-neo4j-graph-1.1.jar, blueprints-graph-jung-1.1.jar, blueprints-neo4jbatch-graph-1.1.jar, blueprints-sail-graph-1.1.jar, blueprints-orient-graph-1.1.jar, collections-generic-4.01.jar, blueprints-rexster-graph-1.1.jar, jta.jar, lucene-core-3.1.0.jar, neo4j-lucene-index-1.6.M01.jar, neo4j-remote-graphdb-0.8-1.2.M06.jar" 
     width="1300" height="700"> 

</applet> 

</body> 
</html> 

我希望代码:width="1300" height="700"为:宽= winW高度= winH。我想要在<applet>标签中给变量值赋予宽度和高度。

有人能告诉我该怎么做吗?

请让我知道,如果我需要澄清。

回答

0

一种方式是编写小程序里面document.writeln()这样的...

document.writeln('<applet code="Dummy.class" width="'+winW+'" height="'+winH+'">'); 
+0

当'deployJava.js'存在时,请不要使用一些没有合理理由的home-rolled脚本(特别是不能关闭applet元素的脚本)。 – 2012-03-14 05:29:09

0

使用deployJava.js写的applet元素。请参阅使用它的一个固定大小的小程序this example ..

<script src="http://www.java.com/js/deployJava.js"></script> 
<script> 
    var attributes = {codebase:'http://java.sun.com/products/plugin/1.5.0/demos/jfc/Java2D', 
         code:'java2d.Java2DemoApplet.class', 
         archive:'Java2Demo.jar', 
         width:710, height:540} ; 
    var parameters = {fontSize:16} ; 
    var version = '1.6' ; 
    deployJava.runApplet(attributes, parameters, version); 
</script> 

你想补充一点,刚刚head部分&改变它的接近像前:

<script src="http://www.java.com/js/deployJava.js"></script> 
<script> 
    var attributes = {codebase:'http://java.sun.com/products/plugin/1.5.0/demos/jfc/Java2D', 
         code:'java2d.Java2DemoApplet.class', 
         archive:'Java2Demo.jar', 
         width:winW, height:winH} ; 
    var parameters = {fontSize:16} ; 
    var version = '1.6' ; 
    deployJava.runApplet(attributes, parameters, version); 
</script> 

一个不支持获取完整窗口小程序的方法是指定宽度和高度100%。如果它可以工作,则应在浏览器窗口调整大小时进行调整。


也许这个程序。最好编码为一个框架并使用Java Web Start从链接启动。动态调整帧比对小应用程序更加可靠。

+0

这也适用于我。感谢您的帮助。 – 2012-03-14 19:05:15