Three Steps to Adding a Component

  public void init() {
     Label label;
     label = new Label("Hello Container");
     this.add(label);
  }

The key thing to remember about adding components to the applet is the three steps:

  1. Declare the component
  2. Initialize the component
  3. Add the component to the layout.

The first two steps must be performed when creating an instance of any class so it's really only the third that's new.

You normally combine the three steps into two like this:

     Label label = new Label("Hello Container");
     this.add(label);

Previous | Next | Top | Cafe au Lait

Copyright 1997, 1999, 2002 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified October 31, 2002