Yurttas/PL/OOL/Java/F/05/02/03/01/Food00.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 Food00 extends Frame
20                    implements ActionListener {
21
22  static public void main(String[] args) {
23    Frame f = new Food00();
24
25    f.setSize(320,160);
26    f.show();
27  }
28
29  private static String[] menuLabels = {"Breakfast",
30                                        "Dinner"};
31  private static int nMenu = menuLabels.length;
32
33  private static Menu[] m;
34  private static MenuBar mB;
35
36  private static String[] breakfastLabels = {"Pancakes",
37                                             "Bagels",
38                                             "Waffles",
39                                             "Continental"};
40  private static final int nBreakfast = breakfastLabels.length;
41
42  private static final String[] dinnerLabels = {"American",
43                                                "Chineese",
44                                                "French",
45                                                "Italian",
46                                                "Japaneese",
47                                                "Korean",
48                                                "Mexican",
49                                                "Russian",
50                                                "Turkish",
51                                                "Vietnameese"};
52  private static int nDinner = dinnerLabels.length;
53
54  public Food00() {
55    super("myEatingPlace");
56    mB = new MenuBar();
57
58    m = new Menu[nMenu];
59
60    for(int i=0; i<nMenu; i++) {
61      m[i] = new Menu(menuLabels[i]);
62
63      switch (i) {
64        case 0: for(int j=0; j<nBreakfast; j++)
65                  m[i].add(breakfastLabels[j]);
66                break;
67        case 1: for(int j=0; j<nDinner; j++)
68                  m[i].add(dinnerLabels[j]);
69      }
70
71      m[i].addActionListener(this);
72      mB.add(m[i]);
73    }
74
75    setMenuBar(mB);
76  }
77
78  public void actionPerformed(final ActionEvent aE) {
79    String arg = aE.getActionCommand();
80
81    for(int i=0; i<nBreakfast; i++)
82      if(arg.equals(breakfastLabels[i])) System.out.println(arg);
83
84    for(int i=0; i<nDinner; i++)
85      if(arg.equals(dinnerLabels[i])) System.out.println(arg);
86
87    repaint();
88  }
89
90}