/** * CardLayoutApplet.java * Copyright (c) 1998 Yoon Kyung Koo. All rights reserved. * * First release date 1998/06/12 * * @version 1.0 1998/06/12 * @author Yoon Kyung Koo */ import java.awt.*; public class CardLayoutApplet extends java.applet.Applet { Choice choice; Panel cardPanel; Button[] button=new Button[5], cardButton=new Button[5]; public void init() { Panel toolPanel=new Panel(); // default (Panel:FlowLayout) toolPanel.add(new Button("first")); toolPanel.add(new Button("previous")); toolPanel.add(new Button("next")); toolPanel.add(new Button("last")); choice= new Choice(); choice.addItem("No. 1"); choice.addItem("No. 2"); choice.addItem("No. 3"); choice.addItem("No. 4"); choice.addItem("No. 5"); toolPanel.add(choice); Panel mainPanel=new Panel(); Panel tabPanel=new Panel(); tabPanel.setLayout(new GridLayout(1, 5)); for (int i=0; i<5; i++) { button[i]=new Button("No. "+(i+1)); button[i].setBackground(new Color(50*(5-i), 50*(5-i), 50*(5-i))); button[i].setForeground(new Color(50*i, 50*i, 50*i)); tabPanel.add(button[i]); } cardPanel=new Panel(); cardPanel.setLayout(new CardLayout()); for (int i=0; i<5; i++) { cardButton[i]=new Button("Card Number = "+(i+1)); cardButton[i].setBackground(new Color(50*(5-i), 50*(5-i), 50*(5-i))); cardButton[i].setForeground(new Color(50*i, 50*i, 50*i)); cardPanel.add("No. "+(i+1), cardButton[i]); } mainPanel.setLayout(new BorderLayout()); mainPanel.add("North", tabPanel); mainPanel.add("Center", cardPanel); setLayout(new BorderLayout()); add("North", toolPanel); add("Center", mainPanel); validate(); } public boolean action(Event evt, Object obj) { if (evt.target instanceof Button || evt.target instanceof Choice ) { String string=(String) obj; if (string.equals("No. 1") || string.equals("No. 2") || string.equals("No. 3") || string.equals("No. 4") || string.equals("No. 5") ) { ((CardLayout) cardPanel.getLayout()).show(cardPanel, (String) obj); return true; } else if (string.equals("first")) { ((CardLayout) cardPanel.getLayout()).first(cardPanel); return true; } else if (string.equals("previous")) { ((CardLayout) cardPanel.getLayout()).previous(cardPanel); return true; } else if (string.equals("next")) { ((CardLayout) cardPanel.getLayout()).next(cardPanel); return true; } else if (string.equals("last")) { ((CardLayout) cardPanel.getLayout()).last(cardPanel); return true; } } return false; } }