import java.applet.*; import java.awt.*; public class flow extends Applet { Frame window = new Frame("This is the Frame's Title Bar!"); Button btn = new Button("Destroy the Frame"); public void init() { add(new Label("The Frame created by this applet has a Border layout.")); add(new Label("Resize the Frame to see how the components")); add(new Label("automatically adjust. Click on an option below and")); add(new Label("the layout of the Frame will change.")); add(new Label("You must use the applet's button to delete the Frame.")); CheckboxGroup align = new CheckboxGroup(); add(new Checkbox("Flow Center Arrangement",align,false)); add(new Checkbox("Flow Right Arrangement",align,false)); add(new Checkbox("Flow Left Arrangement",align,false)); add(new Checkbox("Grid (or GridBag) Arrangement",align,false)); add(new Checkbox("Card (Hyper Card) Arrangement",align,false)); add(new Label("Hit this button to")); add(btn); add(new Label(".")); window.setLayout(new BorderLayout(10,5)); window.add("North",new Button("One")); window.add("South",new Button("Two")); window.add("East",new Button("Three")); window.add("West",new Button("Four")); window.add("Center",new Button("Five")); window.resize(300,200); window.show(); } public boolean action(Event evt, Object whatAction) { if((evt.target instanceof Checkbox)) { Checkbox currentCheckbox = (Checkbox)evt.target; boolean checkboxState = currentCheckbox.getState(); if (currentCheckbox.getLabel() == "Flow Center Arrangement") if (checkboxState) { window.hide(); window.dispose(); window.setLayout(new FlowLayout(FlowLayout.CENTER,2,2)); window.resize(300,200); window.show(); } if (currentCheckbox.getLabel() == "Flow Right Arrangement") if (checkboxState) { window.hide(); window.dispose(); window.setLayout(new FlowLayout(FlowLayout.RIGHT,2,2)); window.resize(300,200); window.show(); } if (currentCheckbox.getLabel() == "Flow Left Arrangement") if (checkboxState) { window.hide(); window.dispose(); window.setLayout(new FlowLayout(FlowLayout.LEFT,2,2)); window.resize(300,200); window.show(); } if (currentCheckbox.getLabel() == "Grid (or GridBag) Arrangement") if (checkboxState) { window.hide(); window.dispose(); window.setLayout(new GridLayout(2,3,5,10)); window.resize(300,200); window.show(); } if (currentCheckbox.getLabel() == "Card (Hyper Card) Arrangement") if (checkboxState) { window.hide(); window.dispose(); window.setLayout(new CardLayout()); window.resize(300,200); window.show(); } return true; } if((evt.target instanceof Button)) { String buttonLabel = (String) whatAction; if (buttonLabel == "Destroy the Frame") { window.hide(); window.dispose(); return true; } } return false; } public Insets insets() { return new Insets(10,20,30,40); } }