java - 在我的小程序中使用 webrenderer 时出现错误

标签 java applet runtime-error

我正在尝试让这段代码工作(小程序),它基于 webrenderer 试用,我在示例部分中得到了这段代码。

虽然我尝试搜索那里的网站,但没有用。我想在我的小程序上呈现页面。 下面是我使用的完整代码,我真的不知道那里出了什么问题。

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import com.webrenderer.swing.*;

/**
 * This example shows how to set up WebRenderer to run Java Applets
 * 
 * @author JadeLiquid Software.
 * @see www.webrenderer.com
 */
public class AppletExample 
{

// instance of a browser
IMozillaBrowserCanvas browser;
JTextField textfield;

public AppletExample() 
{
    // Creates a JFrame to host the browser
    JFrame frame = new JFrame("Applet Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Create and append the browser
    frame.setContentPane(createContent());

    frame.setSize(640, 480);
    frame.setVisible(true);
}

public JPanel createContent() 
{
    JPanel panel = new JPanel(new BorderLayout());
    textfield = new JTextField();

    panel.add(BorderLayout.NORTH, textfield);

    // The action listener triggers when text is entered in the text field
    textfield.addActionListener(new ActionListener() 
    {
        public void actionPerformed(ActionEvent e) 
        {
            browser.loadURL(textfield.getText());
        }
    });

    // If you are behind a proxy server, it may be necessary to set the proxy authentication
    // to enable access for page loading.  Enable the following call(s) with the appropriate
    // values for domain, port..
    // These settings will need to be applied to both the browser and to enable applets.
    //int yourProxyPort = 8080;
    //String yourProxyServer = "proxyserver";

    // Apply proxy settings to enable applets. Username and password will need to entered as  
    // a dialog does not appear automatically as is the case with the browser proxy.
    //BrowserFactory.setAppletProxySettings(yourProxyServer, String.valueOf(yourProxyPort));
    //BrowserFactory.setAppletProxyAuthentication("username", "password");

    // Create a browser instance
    browser = BrowserFactory.spawnMozilla();

    // Required if a proxy server is being used.
    //browser.setProxyProtocol(new ProxySetting( ProxySetting.PROTOCOL_ALL, yourProxyServer, yourProxyPort));
    //browser.enableProxy(); 

    // Required call to allow applets to function
    browser.setAppletMode(IMozillaBrowserCanvas.ENABLE_JAVA_APPLETS);

    // Load a site with many applet examples
    browser.loadURL("java.sun.com/applets/jdk/1.4/index.html");

    // Attach to the panel
    panel.add(BorderLayout.CENTER, browser.getComponent());
    return panel;
}

public static void main(String[] args) 
{
    /*
     * TODO: Insert your username and key in the following setLicenseData call. 
     * WebRenderer operates with reduced functionality if the username and key are not correct.
     * The sample key used below is a limited-duration trial key.
     */
    BrowserFactory.setLicenseData( "30dtrial" , "9Q2QFT9JIK4OHO5BSNKHNMM9EMTR5NRG" );
    new AppletExample();
}
}

当我尝试运行它时出现错误

java.lang.reflect.InvocationTargetException

这是调试信息

Initializing jdb ...
Internal exception:
java.io.IOException: The handle is invalid
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:242)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:273)
at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:154)
at java.io.BufferedReader.readLine(BufferedReader.java:317)
at java.io.BufferedReader.readLine(BufferedReader.java:382)
at com.sun.tools.example.debug.tty.TTY.<init>(TTY.java:751)
at com.sun.tools.example.debug.tty.TTY.main(TTY.java:1067)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at sun.applet.Main.invokeDebugger(Main.java:314)
at sun.applet.Main.run(Main.java:143)
at sun.applet.Main.main(Main.java:98)

最佳答案

请确保您已按照文档中概述的步骤进行操作:http://www.webrenderer.com/products/swing/developer/developersguide/files/appletdeploy.htm

关于java - 在我的小程序中使用 webrenderer 时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13257865/

相关文章:

java - 获取在运行时生成的类的字节

java - 创建新 LAN 套接字时连接被拒绝

c++ - 将对象传递给重载运算符

java - Applet 中的图像未显示在网页中

java - 一行中不能声明超过 2 个数组

递归函数调用期间的 C 运行时错误

java - 无法处理 MustUnderstand header : {http://docs. oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}安全性。返回故障

java - Apache CXF 客户端 soap 故障处理

java - Maven 可以重新签署依赖项吗?

java - 将java小程序的图形内容保存到图像文件无法正常工作