9.6. Building Applets

Like any Java applications, applets are also compiled using the Java compiler. The only difference is that a Java applet is not like a standard application and can be run only inside a browser. Following is a source code for the applet HelloWorld.java that is used as an example here. The applet, when compiled with the Java compiler results in HelloWorld.class file, which is Java byte code.

import java.applet.*;
import java.awt.*;

public class HelloWorld extends java.applet.Applet {
    public void paint (java.awt.Graphics gc) {
  gc.drawString("Hello World", 100, 90);
    }
}

The main thing to note here is that compiling Java applets is not different in any way from compiling Java applications. The only difference between a Java ...

Get Linux Development Platform: Configuring, Using, and Maintaining a Complete Programming Environment, The 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.