Yurttas/PL/OOL/Java/F/05/01/01/04/CLJButtons00.java

Revision as of 14:23, 7 November 2013 by MassBot1 (talk | contribs) (Created page with "<syntaxhighlight lang="java" line start="1" enclose="div">/** * Copyright(C) 2002 * All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc.. * * P...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 1/**
 2 *  Copyright(C) 2002
 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, 2002.
11 *  @author : Salih Yurttas.
12 */
13
14
15import javax.swing.*;
16
17import java.awt.*;
18
19import java.awt.event.*;
20
21public class CLJButtons00 extends JFrame
22                          implements ActionListener {
23
24  public static void main(String[] args) {
25    JFrame jF = new CLJButtons00();
26
27    jF.setSize(400,320);
28    jF.show();
29  }
30
31  private CardLayout cL;
32
33  private JPanel cards;
34
35  private String[] bLabels = {"One",
36                              "Two",
37                              "Three"};
38  private int n = bLabels.length;
39
40  private JButton[] jB;
41
42  public CLJButtons00() {
43
44    setTitle("CLJButtons00");
45
46    cL = new CardLayout();
47    cards = new JPanel();
48
49    cards.setLayout(cL);
50
51    jB = new JButton[n];
52
53    for(int i=0; i<n; i++) {
54      jB[i] = new JButton(bLabels[i]);
55      jB[i].addActionListener(this);
56      Integer n = new Integer(i);
57      cards.add(jB[i], n.toString());
58    }
59
60    this.getContentPane().add("Center", cards);
61  }
62   
63  public void actionPerformed(ActionEvent e) {
64    String arg = e.getActionCommand();
65
66    if (arg.equals("One")) cL.next(cards);
67    else if (arg.equals("Two")) cL.next(cards);
68    else if (arg.equals("Three")) cL.first(cards);
69    repaint();
70  }
71
72}