Swing JApplets

Sun's Swing Tutorial link: How to Make Applets is most useful. This page points to an appropriate page of Getting Started with Applets since much of the Swing materials use the AWT infrastructure, including the AWT event model.

At Features Provided by JApplet it also shows how to add components to the Content Pane

Basically Applets are not much different from applications. In fact, mostly the only difference is how they are started and that for an application, if you want a GUI, you need to instantiate the Frame (or JFrame) to put things on.
Note how example JApplet code shows two methods (the main/init and the createAndShowGUI()/createGUI()) illustrating that starting JApplets are (can be/should be) very similar to starting applications: Swing application HelloWorld


See the applications main method

Now the JApplet's init

The invokeLater [Da Doo Ron Ron] method is not appropriate for some JApplet's because it could allow init to return before initialization is complete, which could cause applet problems that are difficult to debug.


OK, now their building of the GUI:

The applications createAndShowGUI() method

Here is another for a class LabelDemo.java (Labels) which extends JPanel. See how it makes a JFrame, then a LabelDemo (which is a JPanel), then gives the frame the ContentPane of this JPanel. LabelDemo's constructor adds all the components to the JPanel

Now the JApplet's createGUI()

Discuss createAndShowGUI() for applications vs. createGUI() for applets (remember - they "show" on browsers via .html pages)

Note that if the applications and applets use any event-driven aspects, whether using Swing or not will probably need to import both
java.awt.*
java.awt.event.*

A bit more complex IconDemoApp (Icon Demo) and application
In fact, here is the tutorials Table of Examples