GridLayout

Here's the source code:

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

public class Ingredients2 extends Applet {

  TextField t;
  double price = 7.00;

  public void init() {
  
    this.setLayout(new GridLayout(11,1));
    this.add(new Label("What do you want on your pizza?", Label.CENTER));
    this.add(new Checkbox("Pepperoni"));
    this.add(new Checkbox("Olives"));
    this.add(new Checkbox("Onions"));
    this.add(new Checkbox("Sausage"));
    this.add(new Checkbox("Peppers"));
    this.add(new Checkbox("Extra Cheese"));
    this.add(new Checkbox("Ham"));
    this.add(new Checkbox("Pineapple"));
    this.add(new Checkbox("Anchovies"));
    this.t = new TextField("$" + String.valueOf(price));
    // so people can't change the price of the pizza
    this.t.setEditable(false); 
    this.add(this.t);
  }
  
  /* I've removed the code to handle events
  since it isn't relevant to this example, and since I haven't
  had time to port it to 1.1 */

}
Grid layouts are very easy to use. This applet is just three lines different from the previous version and one of those is a change in the name of the class that wasn't really necessary.


Previous | Next | Top
Last Modified April 16, 1998
Copyright 1997, 1998 Elliotte Rusty Harold
elharo@metalab.unc.edu