java – 使用JNLP部署Applet

我正在尝试使用新的Java JNLP规范部署Applet,但我总是收到Java插件控制台的以下错误:

BadFieldException[ Il campo <jnlp><applet-desc>width presenta un valore non valido: 0,0]

这是我的HTML代码:

        <script>
        var attributes = { id:'signingApplet', code:'it.insielmercato.web.signing.SigningApplet' ,width:0, height:0 } ; 
        var parameters = {jnlp_href: 'signing-applet.jnlp'} ; 
        deployJava.runApplet(attributes, parameters, '1.6');
        function setClipboardText(text){
            signingApplet.setClipboardContent(text);
        }
    </script>

这是我的JNLP代码:

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.5+" codebase="" href="">
<information>
    <title>SigningApplet</title>
    <vendor>Insielmercato S.P.A.</vendor>
</information>
<resources>
    <!-- Application Resources -->
    <j2se version="1.6+"
          href="http://java.sun.com/products/autodl/j2se"/>
    <jar href="signing-1.0.jar" main="true" />
</resources>
<applet-desc name="Signing Applet" main-class="it.insielmercato.web.signing.SigningApplet" width="0" height="0">
</applet-desc>
 <update check="background"/>
</jnlp>

和我的小程序代码:

package it.insielmercato.web.signing;

import java.applet.Applet;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;

public class SigningApplet extends Applet implements ClipboardOwner {

/**
 * 
 */
private static final long serialVersionUID = 5272223219287676996L;

private void loadAppletParameters(){

}

public void init(){
    loadAppletParameters();
}

public void setClipboardContent(String text){
    StringSelection ss = new StringSelection(text);
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(ss, this);
}

public void lostOwnership(Clipboard clipboard, Transferable contents) {

}

public String getClipBoardContent(){
    String content = null;
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable contents = clipboard.getContents(null);
    boolean hasTransferableText = (contents != null) &&   contents.isDataFlavorSupported(DataFlavor.stringFlavor);
    if(hasTransferableText)
        try {
            content = (String)contents.getTransferData(DataFlavor.stringFlavor);
        } catch (UnsupportedFlavorException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    return content;
}

}

我哪里错了?

解决方法:

由于“presenta un valore non valido”显然转换为“呈现无效值”,尝试将宽度和高度从0更改为20.

使用CSS(层叠样式表)使applet隐藏或不可见.

上一篇:Java applet与硬件加速3D图形? OpenGL和/或DirectX


下一篇:Javascript到Java Applet的通信