/*
Chapter 6.6:
MyClass
Programmer:
Brad Shedd
Date:
July 17, 2006
Filename:
MyClass.java
Purpose:
This Program displays names of classes.
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;
public
class
MyClasses
extends Frame
implements
ActionListener
{
private
Button keys[];
private
Panel keypad;
private
TextField lcd;
private
boolean foundKey;
public
MyClasses()
{
//construct
components and initialize beginning values
lcd =
new
TextField (20);
lcd.setEditable(false);
keypad =
new
Panel();
keys =
new
Button[9];
//construct
and assing captions to the Buttons
keys[0] =
new
Button("173");
keys[1] =
new
Button("105");
keys[2] =
new
Button("106");
keys[3] =
new
Button("112");
keys[4] =
new
Button("250");
keys[5] =
new
Button("251");
keys[6] =
new
Button("252");
keys[7] =
new
Button("2421");
keys[8] =
new
Button("2441");
//set Frame
and keypad layout to grid layout
setLayout(new
BorderLayout());
keypad.setLayout(new
GridLayout(3,3,10,10));
for
(int i=0; i<=2; i++)
keypad.add(keys[i]);
for
(int i=3; i<=5; i++)
keypad.add(keys[i]);
for
(int i=6; i<=8; i++)
keypad.add(keys[i]);
for
(int i=0; i<keys.length; i++)
keys[i].addActionListener(this);
add(lcd,
BorderLayout.NORTH);
add(keypad,
BorderLayout.CENTER);
addWindowListener(
new
WindowAdapter()
{
public
void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
// end of
constructor method
public
void actionPerformed(ActionEvent e)
{
//test for
button clicks
foundKey =
false;
//search for the clicked key
for
(int i=0; i<keys.length &&
!foundKey; i++)
{
if(e.getSource()
== keys[i])
{
foundKey=true;
switch(i)
{
// keys
case
0:
lcd.setText("PC
Operating Systems Concepts");
break;
case
1:
lcd.setText("Program
Design and Development");
break;
case
2:
lcd.setText("Computer
Concepts");
break;
case
3:
lcd.setText("Systems
Analysis and Design");
break;
case
4:
lcd.setText("Into
to RPG");
break;
case
5:
lcd.setText("Advanced
RPG");
break;
case
6:
lcd.setText("Intro
to Java");
break;
case
7:
lcd.setText("Intermediate
Java");
break;
case
8:
lcd.setText("Advanced
Java");
break;
}
//end switch
}
//end if
}
}//end
actionperformed
public
static
void
main(String args[])
{
//
set frame properties
MyClasses f =
new
MyClasses();
f.setTitle("MyClasses");
f.setBounds(100,130,250,300);
f.setVisible(true);
}//end
main
}// end class