/* ButtonApplet5 shows how panels can be nested. */ import java.applet.*; import java.awt.*; public class ButtonApplet5 extends Applet { Button redButton = new Button("Red"); Button yellowButton = new Button("Yellow"); Button orangeButton = new Button("Orange"); Button blackButton = new Button("Black"); Button blueButton = new Button("Blue"); Button whiteButton = new Button("White"); Panel colorPanel; Panel buttonPanel; public void init() { setLayout(new GridLayout(2, 1)); // Applet has // 2 row, 1 cols buttonPanel = new Panel(); buttonPanel.setLayout(new GridLayout(2, 3)); buttonPanel.add(redButton); buttonPanel.add(yellowButton); buttonPanel.add(orangeButton); buttonPanel.add(blackButton); buttonPanel.add(blueButton); buttonPanel.add(whiteButton); colorPanel = new Panel(); colorPanel.setBackground(Color.white); add(colorPanel); // add colorPanel to applet add(buttonPanel); // add buttonPanel to applet } public boolean action(Event evt, Object arg) { if (evt.target instanceof Button) { if (evt.target == redButton) colorPanel.setBackground(Color.red); else if (evt.target == yellowButton) colorPanel.setBackground(Color.yellow); else if (evt.target == orangeButton) colorPanel.setBackground(Color.orange); else if (evt.target == blackButton) colorPanel.setBackground(Color.black); else if (evt.target == blueButton) colorPanel.setBackground(Color.blue); else colorPanel.setBackground(Color.white); colorPanel.repaint(); return true; } return false; } }