【问题标题】:Load a JFrame into a html将 JFrame 加载到 html 中
【发布时间】:2013-10-16 03:02:33
【问题描述】:

我正在尝试以 html 代码打开我的 Applet.jar。

我的 Java 代码是:

public class NewJFrame extends javax.swing.JFrame {

    public NewJFrame() {
        initComponents();
    }

    private void initComponents() {
        setTitle("Example");
        //more lines code base in JFrame with button,labels etc
    }

    public static void main(String args[]) {
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new NewJFrame().setVisible(true);
            }
        });
    }
}

我的html代码是:

<!DOCTYPE html>
<html>
<body>

<h1>Java Applet Example</h1>

<p><object type="application/x-java-applet" width="300" height="300"> <param name="code" value="NewJFrame.class" /> <param name="archive" value="20130717_Applet.jar" /> <param name="mayscript" value="true" /> Java failed to load </object></p>

</body>
</html>

因此,当我尝试使用浏览器打开 html 文件时,它会让我崩溃:

Java 错误:“ClassNotFoundException NewJFrame.class”

我将 Java 控制面板的安全性从“高”更改为“中”,但我得到了同样的错误。

【问题讨论】:

  • 尝试更改为低。这里不是专家,但我想档案需要数字签名。我可能错了:)
  • 没有“低”选项,最低为中
  • 我看过这篇文章,这就是我将安全性从高更改为中的原因。,..但它不起作用!所以我用我的代码创建了一个新帖子,看看是否有人可以帮助我!
  • &lt;applet&gt; 标签已过时尝试使用&lt;object&gt; 标签。

标签: java html swing jframe


【解决方案1】:

AFAIK 类需要扩展其中一个小程序类以将该类作为小程序运行。

public class NewJFrame extends javax.swing.JApplet {

由于小程序没有提供setTitle 方法(至少不直接提供),所以注释掉该行

setTitle("Example");

要直接使用JFrame 运行应用程序,可以使用Java Web Start

【讨论】:

  • 当我尝试它时,它让我在 java 上的 setTitle 方法出错!
  • 正如您所期望的,小程序没有框架标题。注释掉那一行
  • 我的代码不仅仅是 initComponets 中的这一行。但是我这里只写这行是为了更容易理解!
猜你喜欢
  • 1970-01-01
  • 2012-07-02
  • 1970-01-01
  • 1970-01-01
  • 2013-06-28
  • 2013-08-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多