Peer vs. Swing Components

I'm not going to talk much about Swing in this course, but most of what I teach you about the standard AWT components carries over to their Swing equivalents with only trivial changes. For example, here's yet another way to write an applet that says "Cub Scouts!" in 24 point, SansSerif, bold and blue and with a yellow background.

import java.awt.*;
import javax.swing.*;

public class SwingCubScout extends JApplet {

  public void init() {
     JLabel cubScouts = new JLabel("Cub Scouts!");
     cubScouts.setFont(new Font("Sans", Font.BOLD, 24)); 


This is almost identical to the AWT-based Cub Scout applet, except that I've imported the javax.swing package and changed Label to JLabel and Applet to JApplet.

Cub Scouts applet

Previous | Next | Top | Cafe au Lait

Copyright 1998, 1999, 2002 Elliotte Rusty Harold
Last Modified August 2, 2002