将主类添加到applet

1 java user-interface applet swing awt

我向Java applet添加了一个main方法,以便将其作为应用程序运行,但它要求我初始化包含main的类中的所有方法.我设法初始化该init方法,但我没有初始化所有进行参数的方法.

谁有想法如何进行?

Rei*_*eus 6

这是来自工作应用程序的代码.注意如何调用applet方法:

    JFrame frame = new JFrame();
    frame.setSize(400, 300);

    final Applet applet = new MyCustomApplet();

    frame.getContentPane().add(applet);
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent we) {
            applet.stop();
            applet.destroy();
            System.exit(0);
        }
    });

    frame.setVisible(true);
    applet.init();
    applet.start();
Run Code Online (Sandbox Code Playgroud)

  • 发布您的代码和您看到的任何错误 (2认同)