Yurttas/PL/OOL/Java/F/05/02/01/04/CLButtons00.java
Jump to navigation
Jump to search
1/**
2 * Copyright(C) 1998
3 * All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
4 *
5 * Permission to use, copy, modify, and distribute this
6 * software and its documentation for EDUCATIONAL purposes
7 * and without fee is hereby granted provided that this
8 * copyright notice appears in all copies.
9 *
10 * @date : January 1, 1998.
11 * @author : Salih Yurttas.
12 */
13
14
15import java.awt.*;
16
17import java.awt.event.*;
18
19public class CLButtons00 extends Frame
20 implements ActionListener {
21
22 public static void main(String[] args) {
23 Frame f = new CLButtons00();
24
25 f.setSize(400,320);
26 f.show();
27 }
28
29 private CardLayout cL;
30
31 private Panel cards;
32
33 private String[] bLabels = {"One",
34 "Two",
35 "Three"};
36 private int n = bLabels.length;
37
38 private Button[] b;
39
40 public CLButtons00() {
41
42 setTitle("CLButtons00");
43
44 cL = new CardLayout();
45 cards = new Panel();
46
47 cards.setLayout(cL);
48
49 b = new Button[n];
50
51 for(int i=0; i<n; i++) {
52 b[i] = new Button(bLabels[i]);
53 b[i].addActionListener(this);
54 Integer n = new Integer(i);
55 cards.add(b[i], n.toString());
56 }
57
58 add("Center", cards);
59 }
60
61 public void actionPerformed(ActionEvent e) {
62 String arg = e.getActionCommand();
63
64 if (arg.equals("One")) cL.next(cards);
65 else if (arg.equals("Two")) cL.next(cards);
66 else if (arg.equals("Three")) cL.first(cards);
67 repaint();
68 }
69
70}