我正在尝试将一个工作简单的 Java 应用程序转换为一个小程序。该应用程序由 main.java 和 gooey.java 组成
主.java
package hellow_convert;
import javax.swing.JApplet;
public class main extends JApplet {
public static void main(String[] args) {
gooey gui = new gooey();
}
public void init()
{
gooey gui = new gooey();
}
public void stop() {}
}
gooey.java
package hellow_convert;
import javax.swing.*;
import java.util.*;
import java.awt.*;
public class gooey {
public JFrame f = new JFrame();
private JPanel pnlNorth = new JPanel();
private JButton btnNorth = new JButton("North");
private JMenuBar mb = new JMenuBar(); // MenuBar
private JMenu mnuFile = new JMenu("File"); // File Entry on Menu bar
private JMenuItem mnuItemAbout = new JMenuItem("About"); // About Entry
public gooey(){
f.setJMenuBar(mb);
mb.add(mnuFile);
mb.add(mnuHelp);
pnlNorth.add(btnNorth);
f.getContentPane().setLayout(new BorderLayout());
f.getContentPane().add(pnlNorth, BorderLayout.NORTH);
f.setBounds(100, 100, 200, 100);
}
}
它看起来像这样。
我似乎无法让它作为一个小程序运行。当我在调试中运行它时,会打开一个小程序窗口,然后会弹出 JFrame 窗口(就像在应用程序中一样)。作为一个应用程序,它按预期运行,但是如何将控件放入 Applet 窗口?我是新手。任何帮助表示赞赏!