//PersInfoDriver.java uncomment lines //test driver of PersonalInfo class //uses a JFrame containing a JTextArea for output import java.awt.*; import javax.swing.*; public class PersInfoDriver { public static void main(String [] args) { JFrame outputFrame; Container container; outputFrame = new JFrame(); outputFrame.setSize(700,500); //size of the frame (window) //terminate the program when the window closes: outputFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); container = outputFrame.getContentPane(); //create a textarea of 30 rows by 60 columns JTextArea outputTextArea = new JTextArea(30,60); //add it to the container, with a JScrollPane container.add( new JScrollPane(outputTextArea)); outputFrame.setVisible(true); //otherwise the window doesn't show... //array of 100 PersonalInfo objects. PersonalInfo [] people = new PersonalInfo[100]; String command; int month, day, year, id; String fname, lname; do { command = JOptionPane.showInputDialog(null, "Enter command: \n Pers\n PersCopy\n PersString\n\n equals\n increment\n toString\n quit", "PersonalInfo driver input", JOptionPane.QUESTION_MESSAGE); if (command.equalsIgnoreCase("Pers")) { //all-values constructor fname = JOptionPane.showInputDialog("Enter first name"); lname = JOptionPane.showInputDialog("Enter last name"); id = Integer.parseInt(JOptionPane.showInputDialog("Enter ID")); month = Integer.parseInt(JOptionPane.showInputDialog("Enter month")); day = Integer.parseInt(JOptionPane.showInputDialog("Enter day")); year = Integer.parseInt(JOptionPane.showInputDialog("Enter year")); people[getIndex()] = new PersonalInfo(fname,lname,month,day,year,id); } else if (command.equalsIgnoreCase("toString")) { outputTextArea.append(people[getIndex()] + "\n"); } /* //**** HMK Date string constructor. //**** HMK PersonalInfo constructor with Person and Date parameters else if (command.equalsIgnoreCase("PersString")) { fname = JOptionPane.showInputDialog("Enter first name"); lname = JOptionPane.showInputDialog("Enter last name"); Person person = new Person(fname,lname); id = Integer.parseInt(JOptionPane.showInputDialog("Enter ID")); String stringDate = JOptionPane.showInputDialog("Enter date as mm-dd-yyyy"); Date date = new Date(stringDate); people[getIndex()] = new PersonalInfo(person,id,date); } //**** HMK PersonalInfo copy constructor else if (command.equalsIgnoreCase("PersCopy")) { int fromIndex = Integer.parseInt(JOptionPane.showInputDialog("Enter index of object to copy from")); people[getIndex()] = new PersonalInfo(people[fromIndex]); } //**** HMK PersonalInfo equals method else if (command.equalsIgnoreCase("equals")) { int objIndex = Integer.parseInt(JOptionPane.showInputDialog("Enter index of PersonalInfo object")); int argIndex = Integer.parseInt(JOptionPane.showInputDialog("Enter index of argument PersonalInfo object")); if (people[objIndex].equals(people[argIndex])) outputTextArea.append("same person\n"); else outputTextArea.append("different persons\n"); } //**** HMK increment Date else if (command.equalsIgnoreCase("increment")) { people[getIndex()].increment(); } */ } while(!command.equalsIgnoreCase("quit")); System.exit(0); } //***input int from user for array index. //could add some checking to ensure index is valid...to avoid subsequent crash public static int getIndex() { return Integer.parseInt(JOptionPane.showInputDialog("Enter index of object to access")); } }