【问题标题】:Java JApplet just displays grey on webpageJava JApplet 只是在网页上显示为灰色
【发布时间】:2013-06-08 11:07:13
【问题描述】:

因此,对于一项任务,我必须制作一个小的 Java 小程序并将其显示在网页上。它在 NetBeans 中构建得很好,但是当我尝试在网页中运行它时,它显示为灰色,如下所示:

import java.awt.GridBagConstraints;
    import java.lang.reflect.InvocationTargetException;
    import javax.swing.JButton;
    import javax.swing.JTextArea;

    public class PlanZajecJavaProjektApplet extends javax.swing.JApplet {

        /**
         * Initializes the applet PlanZajecJavaProjektApplet
         */
        public static int licznikTextFields = 0;
        int dzienLekcji;
        int godzinaLekcji;
        int ileGodzinLekcji;
        private GridBagConstraints gridBagConstraints;
        private JButton button;

        @Override
        public void init() {
            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 | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(PlanZajecJavaProjektApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>

            /* Create and display the applet */
            try {
                java.awt.EventQueue.invokeAndWait(new Runnable() {
                    @Override
                    public void run() {
                        initComponents();

                    }
                });
            } catch (InterruptedException | InvocationTargetException ex) {
            }
        }

        /**
         * This method is called from within the init() method to initialize the
         * form. WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")

那么有什么问题呢?

【问题讨论】:

  • 同时显示initComponents 的代码。并且永远不要将catch 块留空。在其中打印异常的stacktrace
  • pastebin.com/Gn8btFqK 是 Netbeans 生成的代码。
  • 我打印了stacktrace,现在Java控制台显示i.imgur.com/voOjuZJ.jpg

标签: java browser netbeans applet japplet


【解决方案1】:

如堆栈跟踪中所示,您的小程序似乎没有权限执行它想做的事情。

第 51 行从您的代码中删除以下行:

setStub(null);

【讨论】:

  • 但是如何从方法 InitComponents 编辑代码?此代码由 Netbeans 生成,我使用设计模式添加元素。
  • 不,我无法编辑此代码。我新建了一个项目,在面板上加了一个按钮,情况也是一样,小程序只显示灰色矩形。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-13
  • 2020-11-26
  • 2011-12-03
  • 1970-01-01
  • 2023-03-13
相关资源
最近更新 更多