Java JApplet只在网页上显示灰色

Java JApplet只在网页上显示灰色,java,browser,netbeans,applet,japplet,Java,Browser,Netbeans,Applet,Japplet,因此,对于一项作业,我必须制作一个小Java小程序,并将其显示在网页上。它在NetBeans中构建得很好,但当我尝试在网页中运行它时,它显示为灰色,如下所示: 导入java.awt.gridbag约束; 导入java.lang.reflect.InvocationTargetException; 导入javax.swing.JButton; 导入javax.swing.JTextArea; 公共类PlanZajecJavaProjektApplet扩展javax.swing.JApplet{

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

导入java.awt.gridbag约束;
导入java.lang.reflect.InvocationTargetException;
导入javax.swing.JButton;
导入javax.swing.JTextArea;
公共类PlanZajecJavaProjektApplet扩展javax.swing.JApplet{
/**
*初始化小程序PlanZajecJavaProjektApplet
*/
公共静态int-licznikTextFields=0;
国际dzienLekcji;
内戈兹纳列克奇;
国际ileGodzinLekcji;
私有gridbag约束gridbag约束;
私人按钮;
@凌驾
公共void init(){
试一试{
for(javax.swing.UIManager.LookAndFeelInfo:javax.swing.UIManager.getInstalledLookAndFeels()){
if(“Nimbus”.equals(info.getName())){
setLookAndFeel(info.getClassName());
打破
}
}
}catch(ClassNotFoundException |实例化Exception | IllegalacessException | javax.swing.UnsupportedLookAndFeelException ex){
getLogger(PlanZajecJavaProjektApplet.class.getName()).log(java.util.logging.Level.SEVERE,null,ex);
}
//
/*创建并显示小程序*/
试一试{
java.awt.EventQueue.invokeAndWait(new Runnable()){
@凌驾
公开募捐{
初始化组件();
}
});
}捕获(InterruptedException | InvocationTargetException ex){
}
}
/**
*从init()方法中调用此方法来初始化
*表单.警告:请勿修改此代码。此方法的内容为
*始终由表单编辑器重新生成。
*/
@抑制警告(“未选中”)

那么有什么问题呢?

如stacktrace所示,您的小程序似乎没有权限执行它想要执行的操作

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


同时显示
initComponents
的代码..并且永远不要将
catch
块留空。打印其中异常的
stacktrace
。它是由Netbeans生成的代码。我打印了stacktrace,现在Java控制台显示了,但是我如何编辑来自方法initComponents的代码?此代码是由Netbeans生成的,我使用了design mode添加元素。不,我不能编辑这段代码。我创建了一个新项目,并在面板上添加了一个按钮,情况是一样的,小程序只显示灰色的矩形。
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")
setStub(null);