Java applet在网页上运行时只显示灰色

时间:2013-04-11 01:02:44

标签: java applet webpage

因此,对于作业,我必须制作一个小Java小程序并将其显示在网页上。它在NetBeans中构建得很好,但是当我尝试在网页中运行它时,它显示为灰色,如下所示:http://devii.in/7apW我硬盘上的.jar文件加载完全正常,所以我很困惑什么弄乱了它。任何帮助,将不胜感激。谢谢。

您可以自己在这里查看:http://trainman1405.com/hi.html 罐子:http://trainman1405.com/Apples.jar

我的代码:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Apples extends JApplet  {
    private static void display() {
        JTextField field1 = new JTextField();
        JTextField field2 = new JTextField();
        JTextField field3 = new JTextField();
        JTextField field4 = new JTextField();
        JTextField field5 = new JTextField();
        JPanel panel = new JPanel(new GridLayout(0, 1));
        panel.add(new JLabel("Username:"));
        panel.add(field1);
        panel.add(new JLabel("Password:"));
        panel.add(field2);
        panel.add(new JLabel("Repeat Password:"));
        panel.add(field3);
        panel.add(new JLabel("Email address:"));
        panel.add(field4);
        panel.add(new JLabel("Repeat email address:"));
        panel.add(field5);
        int result = JOptionPane.showConfirmDialog(null, panel, "Form",
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
    }
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                display();
            }
        });
    }
}

1 个答案:

答案 0 :(得分:3)

启动applet时,永远不会调用main方法。 applet的入口点是init方法:

public void init() {
   EventQueue.invokeLater(new Runnable() {

      @Override
      public void run() {
        display();
      }
   });
}