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