Tuesday, November 4, 2008

PanelApplet

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

// PanelApplet
//
// The PanelApplet applet creates a number of panels and
// adds buttons to them to demonstrate the use of panels
// for grouping components.

public class PanelApplet extends Applet{

public void init(){

// Create the main panels
Panel mainPanel1 = new Panel();
Panel mainPanel2 = new Panel();

// Create the sub-panels
Panel subPanel1 = new Panel();
Panel subPanel2 = new Panel();

// Add a button directly to the applet
add(new Button("Applet Button"));

// Add the main panels to the applet
add(mainPanel1);
add(mainPanel2);

// Give mainPanel1 a button and a sub-panel
mainPanel1.add(new Button("Main Panel 1 Button"));
mainPanel1.add(subPanel1);

// Give mainPanel2 a button and a sub-panel
mainPanel2.add(new Button("Main Panel 2 Button"));
mainPanel2.add(subPanel2);

// Give each sub-panel a button
subPanel1.add(new Button("Sub-panel 1 Button"));
subPanel2.add(new Button("Sub-panel 2 Button"));
}
}