/* Kevin Fleming
   Final Exam
   Due 5/11/98
   Address book that allows ten contacts
*/

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class AddressBook extends Applet implements ActionListener {
        private Label addressLabel, nameLabel, phoneLabel;
        public static TextField addressText, nameText, phoneText;
        private Button enter, display;
        public static TextArea area;
        public static int count = 1;
        private Contact c;

        public void init()
        {
                c = new Contact();

                nameLabel = new Label("New Contact's Name");
                addressLabel = new Label("New Contact's Address");
                phoneLabel = new Label("New Contact's Telephone #");

                nameText = new TextField(25);
                addressText = new TextField(30);
                phoneText = new TextField(20);

                enter = new Button("Add Contact");
                display = new Button("Display ALL Contacts in DOS");
                area = new TextArea(12, 45);
                area.setEditable(false);
                area.setText("");

                add(nameLabel);
                add(nameText);
                add(addressLabel);
                add(addressText);
                add(phoneLabel);
                add(phoneText);
                add(enter);
                enter.addActionListener(this);
                add(display);
                display.addActionListener(this);                
                add(area);

        }

        public void actionPerformed(ActionEvent e)
        {
                if(e.getSource() == enter)
                {
                        if(count < 11)
                        {
                                area.append(count + ". " + nameText.getText() + ": " + addressText.getText() + "  (" + phoneText.getText() + ")\n");

                                if(count == 1)
                                        c.con1 = "1. " + nameText.getText() + ": " + addressText.getText() + "(" + phoneText.getText() + ")";
                                else if(count == 2)
                                        c.con2 = "2. " + nameText.getText() + ": " + addressText.getText() + "(" + phoneText.getText() + ")";
                                else if(count == 3)
                                        c.con3 = "3. " + nameText.getText() + ": " + addressText.getText() + "(" + phoneText.getText() + ")";
                                else if(count == 4)
                                        c.con4 = "4. " + nameText.getText() + ": " + addressText.getText() + "(" + phoneText.getText() + ")";
                                else if(count == 5)
                                        c.con5 = "5. " + nameText.getText() + ": " + addressText.getText() + "(" + phoneText.getText() + ")";
                                else if(count == 6)
                                        c.con6 = "6. " + nameText.getText() + ": " + addressText.getText() + "(" + phoneText.getText() + ")";
                                else if(count == 7)
                                        c.con7 = "7. " + nameText.getText() + ": " + addressText.getText() + "(" + phoneText.getText() + ")";
                                else if(count == 8)
                                        c.con8 = "8. " + nameText.getText() + ": " + addressText.getText() + "(" + phoneText.getText() + ")";
                                else if(count == 9)
                                        c.con9 = "9. " + nameText.getText() + ": " + addressText.getText() + "(" + phoneText.getText() + ")";
                                else if(count == 10)
                                        c.con10 = "10. " + nameText.getText() + ": " + addressText.getText() + "(" + phoneText.getText() + ")";

                                count++;
                        }
                        else
                                showStatus("Address Book is Full");

                        nameText.setText("");
                        addressText.setText("");
                        phoneText.setText("");
                }

                else if(e.getSource() == display)
                {
                        System.out.println("Contents of Address Book:");

                        System.out.println(c.con1);
                        System.out.println(c.con2);
                        System.out.println(c.con3);
                        System.out.println(c.con4);
                        System.out.println(c.con5);
                        System.out.println(c.con6);
                        System.out.println(c.con7);
                        System.out.println(c.con8);
                        System.out.println(c.con9);
                        System.out.println(c.con10);
                }
        }
}

class Contact {
        public static String con1, con2, con3, con4, con5, con6, con7, con8, con9, con10;

        public Contact()
        {
                con1 = "1. ";
                con2 = "2. ";
                con3 = "3. ";
                con4 = "4. ";
                con5 = "5. ";
                con6 = "6. ";
                con7 = "7. ";
                con8 = "8. ";
                con9 = "9. ";
                con10 = "10. ";

        }
}