你也許能夠使用的結構是這樣的:
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class AppletBasic extends JApplet
{
/**
* Create the GUI. For thread safety, this method should
* be invoked from the event-dispatching thread.
*/
private void createGUI()
{
JLabel appletLabel = new JLabel("I'm a Swing Applet");
appletLabel.setHorizontalAlignment(JLabel.CENTER);
appletLabel.setFont(new Font("Serif", Font.PLAIN, 36));
add(appletLabel);
setSize(400, 200);
}
@Override
public void init()
{
try
{
SwingUtilities.invokeAndWait(new Runnable()
{
public void run()
{
createGUI();
}
});
}
catch (Exception e)
{
System.err.println("createGUI didn't successfully complete: " + e);
}
}
public static void main(String[] args)
{
JApplet applet = new AppletBasic();
applet.init();
JFrame frame = new JFrame("Applet in Frame");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setJMenuBar(applet.getJMenuBar());
frame.setContentPane(applet.getContentPane());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
applet.start();
}
}
如果類加載的是執行小程序的小程序。
如果類裝載到JVM則main()方法被調用,小應用程序組件被添加到JFrame。
考慮完全傾倒的小程序,併爲「斷網」的選項,使用從鏈接啓動框[Java Web Start的(http://stackoverflow.com/tags/java-web-start/info)。 –