O'Reilly logo

Java Garage by Eben Hewitt

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

Writing an Applet

Let's just write an applet and try to view it and see what comes out of the woodwork, shall we?

SimpleApplet.java

package net.javagarage.applets;

import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;

/**
 * <p>
 * Example of very simple JApplet.
 * @author eben hewitt
 */
public class SimpleApplet extends JApplet {

public void init() {
Container content = getContentPane();
content.setBackground(Color.PINK);
content.setLayout(new FlowLayout());
content.add(new JLabel("Hello, world"));
content.add(new JButton("Poke me"));
   }

}

This applet doesn't do much at all. You see a label, you see a button, you press the button, nothin' ...

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