import java.applet.Applet; import java.awt.*; public class CardLayout1 extends Applet { private CardLayout cardLayout; private Panel cardPanel; private List list; public void init() { cardLayout = new CardLayout(); Panel controlPanel = new Panel(); controlPanel.setBackground(Color.pink); controlPanel.add(new Button("Buttons")); controlPanel.add(new Button("TextFields")); controlPanel.add(new Button("Lists")); cardPanel = new Panel(); cardPanel.setLayout(cardLayout); Panel buttonsPanel = new Panel(); buttonsPanel.setBackground(Color.yellow); buttonsPanel.add(new Button("Button 1")); buttonsPanel.add(new Button("Button 2")); buttonsPanel.add(new Button("Button 3")); Panel textFieldsPanel = new Panel(); textFieldsPanel.setBackground(Color.cyan); textFieldsPanel.add(new TextField(10)); String msg = "Please enter your name"; textFieldsPanel.add(new TextField(msg, 40)); Panel listsPanel = new Panel(); listsPanel.setBackground(Color.magenta); list = new List(5, false); list.addItem("Hamlet"); list.addItem("Claudius"); list.addItem("Gertrude"); list.addItem("Polonius"); list.addItem("Horatio"); list.addItem("Laertes"); list.addItem("Ophelia"); list.addItem("Caesar"); list.addItem("Brutus"); list.addItem("Alexandrius"); listsPanel.add(list); Panel welcomePanel = new Panel(); welcomePanel.setBackground(Color.gray); welcomePanel.add(new Label("Welcome to an example of CardLayout")); cardPanel.add("card 1", welcomePanel); cardPanel.add("card 2", buttonsPanel); cardPanel.add("card 3", textFieldsPanel); cardPanel.add("card 4", listsPanel); setLayout(new BorderLayout()); add("North",controlPanel); add("Center",cardPanel); } public boolean action(Event evt, Object arg) { if (arg.equals("Buttons")) { cardLayout.show(cardPanel, "card 2"); } else if (arg.equals("TextFields")) { cardLayout.show(cardPanel, "card 3"); } else if (arg.equals("Lists")) { cardLayout.show(cardPanel, "card 4"); } else return super.action(evt,arg); return true; } }