Combining Applet and Application Code

There are a number of ways to write a Java program so that it can execute either from within a browser or as a standalone application. One way to do this is to center an Applet within a Frame, as in Example 2-3.

Example 2-3. Combining Applet and Application Code
 import java.applet.Applet; import java.awt.Event; import java.awt.Frame; import java.awt.Label; import java.awt.event.*; public class StarterCombined extends Applet { private Label label; public static void main(String args[]) { StarterCombinedFrame app = new StarterCombinedFrame("Starter Application"); app.setSize(300,100); app.show (); System.out.println("StarterCombinedFrame::main()"); ...

Get Graphic Java™ 1.2, Volume I: AWT, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.