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 private String[] sortLabel = {"BubbleSort",
23 "InsertionSort",
24 "SelectionSort",
25 "QuickSort"};
26 private int nSort = sortLabel.length;
27
28 private String[] searchLabel = {"LinearSearch",
29 "BinarySearch"};
30 private int nSearch = searchLabel.length;
31
32 private String[] menuLabel = {"Sort",
33 "Search"};
34 private int nMenu = menuLabel.length;
35
36 private Menu[] m = new Menu[nMenu];
37
38 public Menu04() {
39 super("Menu Example - 04");
40 MenuBar mb = new MenuBar();
41
42 for(int i=0; i<nMenu; i++) {
43 m[i] = new Menu(menuLabel[i]);
44 }
45
46 for(int i=0; i<nSort; i++) {
47 m[0].add(sortLabel[i]);
48 }
49
50 for(int i=0; i<nSearch; i++) {
51 m[1].add(searchLabel[i]);
52 }
53
54 // Add listener for menu
55 for(int i=0; i<nMenu; i++) {
56 m[i].addActionListener(this); // Add ActionListener to menu
57 mb.add(m[i]); // Add menu to menu bar
58 }
59
60 // Set menu bar on frame.
61 setMenuBar(mb);
62
63 setSize(320, 160);
64 show();
65 }
66
67 // Action handler for menu
68
69 public void actionPerformed(ActionEvent e) {
70 String arg = e.getActionCommand();
71
72 for(int i=0; i<nSort; i++)
73 if (arg.equals(sortLabel[i])) System.out.println(arg);
74
75 for(int i=0; i<nSearch; i++)
76 if (arg.equals(searchLabel[i])) System.out.println(arg);
77
78 repaint();
79 }
80
81 static public void main(String[] args) {
82 new Menu04();
83 }
84
85}