//Created by na
//Computer Science ISP
//Last modified: January 13, 2005
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.*;
public class phonebook extends JApplet implements ActionListener
{
//JButton[] buttons = new JButton [5];
int numbercounter = 2; //counts the number of entries the user will make
Container panel = new Container ();
JButton EnterData = new JButton ("Enter Data"); //Button to enter Data
JFrame FirstFrame = new JFrame ("PhoneBook Storage"); //main frame with the 3 starting options
JButton ShowChart = new JButton ("Show Table"); //Button display chart of data
JButton Exit = new JButton ("Close"); //button to exit program
JButton[] buttons = new JButton [numbercounter];
JFrame TypeWindowFrame = new JFrame ("Enter Your Data"); //Frame that you can enter your data into
Container TypeWindow = new Container ();
public void init ()
{
panel.setLayout (new GridBagLayout ());
GridBagConstraints c = new GridBagConstraints ();
JLabel PhoneBook = new JLabel (" Personal PhoneBook"); //Stores the title PhoneBook
c.ipadx = 5;
c.ipady = 1;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1.0;
c.weighty = 1.0;
c.gridx = 0;
c.gridy = 0;
panel.add (PhoneBook, c);
c.gridx = 0;
c.gridy = 1;
panel.add (EnterData, c);
c.gridx = 0;
c.gridy = 2;
panel.add (ShowChart, c);
c.gridx = 0;
c.gridy = 3;
panel.add (Exit, c);
EnterData.addActionListener (this);
ShowChart.addActionListener (this);
Exit.addActionListener (this);
PhoneBook.setForeground (Color.red);
PhoneBook.setBackground (Color.black);
PhoneBook.setOpaque (true);
EnterData.setForeground (Color.black);
EnterData.setBackground (Color.yellow);
EnterData.setOpaque (true);
ShowChart.setForeground (Color.black);
ShowChart.setBackground (Color.yellow);
ShowChart.setOpaque (true);
Exit.setForeground (Color.black);
Exit.setBackground (Color.yellow);
Exit.setOpaque (true);
FirstFrame.setSize (140, 250);
FirstFrame.getContentPane ().add (panel);
FirstFrame.setVisible (true);
}
public void actionPerformed (ActionEvent e)
{
//------------------------------------Enter Data Frame-----------------------------------------
TypeWindow.setLayout (new GridBagLayout ());
GridBagConstraints d = new GridBagConstraints ();
JLabel PleaseEnter = new JLabel (" Enter data in the fields below"); //Stores the title instructions
d.ipadx = 5;
d.ipady = 1;
d.fill = GridBagConstraints.BOTH;
d.weightx = 1.0;
d.weighty = 1.0;
d.gridx = 0;
d.gridy = 0;
TypeWindow.add (PleaseEnter, d);
for (int x = 0 ; x < numbercounter ; x++)
{
d.gridx = x;
d.gridy = 1;
TypeWindow.add (buttons [x], d);
}
TypeWindowFrame.setSize (500, 500);
TypeWindowFrame.getContentPane ().add (TypeWindow); //adds the container to the new frame
TypeWindowFrame.setVisible (false); //sets the frame invisible
//-----------------------------------Show Chart Frame------------------------------------------
//-----------------------------------Exit -----------------------------------------------------
if (e.getSource () == EnterData)
{
FirstFrame.setVisible (false);
TypeWindowFrame.setVisible (true); //sets the Enter data frame visible after the person clicks
}
else if (e.getSource () == ShowChart)
{
FirstFrame.setVisible (false);
TypeWindowFrame.setVisible (true); //sets the showchart frame visible after the person clicks
}
else if (e.getSource () == Exit)
{
FirstFrame.setVisible (false);
TypeWindowFrame.setVisible (true); //sets the exit frame visible after the person clicks
}
}
}
|