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' ...

Get Java Garage 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.