Yurttas/PL/OOL/Java/F/05/02/03/00/Menu03.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 Menu03 extends Frame
20 implements ActionListener {
21
22 static public void main(String[] args) {
23 Frame f = new Menu03();
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 Menu03() {
47 super("Menu - 03");
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
56 for(int i=0; i<nSearch; i++) {
57 m[0].add(searchLabels[i]);
58 }
59
60 for(int i=0; i<nSort; i++) {
61 m[1].add(sortLabels[i]);
62 }
63
64 for(int i=0; i<nMenu; i++) {
65 m[i].addActionListener(this);
66 mB.add(m[i]);
67 }
68
69 setMenuBar(mB);
70 }
71
72 public void actionPerformed(final ActionEvent aE) {
73 String arg = aE.getActionCommand();
74
75 for(int i=0; i<nSearch; i++)
76 if(arg.equals(searchLabels[i])) System.out.println(arg);
77
78 for(int i=0; i<nSort; i++)
79 if(arg.equals(sortLabels[i])) System.out.println(arg);
80
81 repaint();
82 }
83
84}