//---------------------------------------------------------------------------- // TDIncDate241.java by Dale/Joyce/Weems Chapter 1 // modified to be interactive. ch01 // Test Driver for the IncDate class //---------------------------------------------------------------------------- import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; public class TDIncDate241 { public static void main(String[] args) { String testName = "IncDate"; String command = null; int numCommands = 0; IncDate theDate = new IncDate(0,0,0); int month, day, year; System.out.println("Results "); System.out.println(); command = JOptionPane.showInputDialog("Enter command: \n" + " IncDate\n yearIs\n monthIs\n dayIs\n increment\n quit"); //Process commands while(!command.equalsIgnoreCase("quit")) { if (command.equalsIgnoreCase("IncDate")) { month = Integer.parseInt(JOptionPane.showInputDialog("Enter month")); day = Integer.parseInt(JOptionPane.showInputDialog("Enter day")); year = Integer.parseInt(JOptionPane.showInputDialog("Enter year")); System.out.println("Constructor invoked with " + month + " " + day + " " + year); theDate = new IncDate(month, day, year); } else if (command.equalsIgnoreCase("yearIs")) { System.out.println("Year is " + theDate.yearIs()); } else if (command.equalsIgnoreCase("monthIs")) { System.out.println("Month is " + theDate.monthIs()); } else if (command.equalsIgnoreCase("dayIs")) { System.out.println("Day is " + theDate.dayIs()); } else if (command.equalsIgnoreCase("increment")) { theDate.increment(); System.out.println("increment invoked "); } System.out.println("theDate: " + theDate); numCommands++; command = JOptionPane.showInputDialog("Enter command: \n" + " IncDate\n yearIs\n monthIs\n dayIs\n increment\n quit"); } //Set up output frame JFrame outputFrame = new JFrame(); outputFrame.setTitle("Testing " + testName); outputFrame.setSize(300,100); outputFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Instantiate content pane and information panel Container contentPane = outputFrame.getContentPane(); JPanel infoPanel = new JPanel(); // set layout infoPanel.setLayout(new GridLayout(2,1)); // create labels JLabel countInfo = new JLabel(numCommands + " commands completed. "); JLabel finishedInfo = new JLabel("Testing completed. Close window to exit program."); // add information infoPanel.add(countInfo); infoPanel.add(finishedInfo); contentPane.add(infoPanel); // show information outputFrame.show(); } }