1

我是新手,这可能是一个简单的解决方法。我目前正在使用 javascript 获取窗口高度和宽度,并希望使用 javascript 变量设置小程序的高度和宽度。

这是我的代码:

<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>标签中的宽度和高度。

有人可以告诉我该怎么做吗?

如果我需要澄清,请告诉我。

4

2 回答 2

0

一种方法是像这样在里面编写小程序document.writeln()......

document.writeln('<applet code="Dummy.class" width="'+winW+'" height="'+winH+'">');
于 2012-03-13T23:51:50.670 回答
0

使用deployJava.js编写小程序元素。请参阅将其用于固定大小的小程序的此示例。

<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从链接启动。动态调整框架大小比为小程序这样做更容易和更可靠。

于 2012-03-14T05:27:00.903 回答