Back to Applets page
Click in the boxes below, select all and copy to grab the applet
HTML listing:
<HTML> <HEAD> <TITLE>Listing 9.8</TITLE> </HEAD> <BODY BGCOLOR=WHITE> <APPLET CODEBASE="classes" CODE="Applet8.class" WIDTH=400 HEIGHT=100> </APPLET> </BODY> </HTML>
Applet listing:
import java.awt.*; import java.applet.*; public class Applet8 extends Applet { Panel cards, direction; CardLayout layout; public void init() { setBackground(Color.white); direction = new Panel(); direction.add(new Button("<")); direction.add(new Button(">")); cards = new Panel(); layout = new CardLayout(); cards.setLayout(layout); for (int i = 0; i<10; i++) { cards.add(new Button("Card #" + i)); } this.setLayout(new BorderLayout(30,30)); add("North", direction); add("Center", cards); } public boolean action(Event evt, Object arg) { if (evt.target instanceof Component && ((Component)evt.target).getParent().equals(direction)) { if (arg.equals("<")) { layout.previous(cards); return true; } if (arg.equals(">")) { layout.next(cards); return true; } } return super.action(evt, arg); } }