O'Reilly logo

Graphic Java™ 1.2, Volume I: AWT, Third Edition by David M. Geary

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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()"); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required