Yurttas/PL/OOL/Java/F/05/02/02/07/Menu05.java

From ZCubes Wiki
Revision as of 14:47, 7 November 2013 by MassBot1 (talk | contribs) (Created page with "<syntaxhighlight lang="java" line start="1" enclose="div">/** * Copyright(C) 1998 * All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc.. * * P...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 Menu05 extends Frame
20		    implements ActionListener {
21
22  private String[] menuLabel = {"Sort",
23                                "Search"};
24  private int nMenu = menuLabel.length;
25
26  private Menu[] m = new Menu[nMenu];
27
28  private String[] sortLabel = {"BubbleSort",
29                                "InsertionSort",
30                                "SelectionSort",
31                                "QuickSort"};
32  private int nSort = sortLabel.length;
33
34  private String[] searchLabel = {"LinearSearch",
35                                  "BinarySearch"};
36  private int nSearch = searchLabel.length;
37
38  public Menu05() {
39    super("Menu Example - 05");
40    MenuBar mb = new MenuBar();
41
42    for(int i=0; i<nMenu; i++) {
43      m[i] = new Menu(menuLabel[i]);
44
45      switch (i) {
46        case 0: for(int j=0; j<nSort; j++)
47                  m[i].add(sortLabel[j]);
48                break;
49        case 1: for(int j=0; j<nSearch; j++)
50                  m[i].add(searchLabel[j]);
51      }
52
53      m[i].addActionListener(this); // Add ActionListener to menu
54      mb.add(m[i]);                 // Add menu to menu bar
55    }
56
57    // Set menu bar on frame.
58    setMenuBar(mb);
59
60    setSize(320, 160);
61    show();
62  }
63
64  // Action handler for menu
65
66  public void actionPerformed(ActionEvent e) {
67    String arg = e.getActionCommand();
68
69    for(int i=0; i<nSort; i++)
70      if (arg.equals(sortLabel[i])) System.out.println(arg);
71
72    for(int i=0; i<nSearch; i++)
73      if (arg.equals(searchLabel[i])) System.out.println(arg);
74
75    repaint();
76  }
77
78  static public void main(String[] args) {
79    new Menu05();
80  }
81
82}