Yurttas/PL/OOL/Java/F/05/01/03/00/Menu04.java

From ZCubes Wiki
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 Menu04 extends Frame
20                    implements ActionListener {
21
22  static public void main(String[] args) {
23    Frame f = new Menu04();
24
25    f.setSize(320,160);
26    f.show();
27  }
28
29  private static MenuBar mB;
30  private static Menu[] m;
31
32  private static String[] menuLabels = {"Search",
33                                        "Sort"};
34  private static int nMenu = menuLabels.length;
35
36  private static final String[] searchLabels = {"LinearSearch",
37                                                "BinarySearch"};
38  private static int nSearch = searchLabels.length;
39
40  private static String[] sortLabels = {"BubbleSort",
41                                        "InsertionSort",
42                                        "QuickSort",
43                                        "SelectionSort"};
44  private static final int nSort = sortLabels.length;
45
46  public Menu04() {
47    super("Menu - 04");
48    mB = new MenuBar();
49
50    m = new Menu[nMenu];
51
52    for(int i=0; i<nMenu; i++) {
53      m[i] = new Menu(menuLabels[i]);
54
55      switch(i) {
56        case 0: for(int j=0; j<nSearch; j++)
57                  m[i].add(searchLabels[j]);
58                break;
59        case 1: for(int j=0; j<nSort; j++)
60                  m[i].add(sortLabels[j]);
61      }
62
63      m[i].addActionListener(this);
64      mB.add(m[i]);
65    }
66
67    setMenuBar(mB);
68  }
69
70  public void actionPerformed(final ActionEvent aE) {
71    String arg = aE.getActionCommand();
72
73    for(int i=0; i<nSearch; i++)
74      if(arg.equals(searchLabels[i])) System.out.println(arg);
75
76    for(int i=0; i<nSort; i++)
77      if(arg.equals(sortLabels[i])) System.out.println(arg);
78
79    repaint();
80  }
81
82}