Computer Science 241
Assignment 4
Due: March 5, 2002

For this assignment, add a second frame to your project for assignment 3.  It will be used to either find an object in the array or to add a new object.  It should have labels and boxes that will display a single object.  It should also have one button that will find and display an object in the boxes and another that can be used to add a new object to the array.  You will probably also want a third button to hide the second frame and return you to the first one.

The second frame will need boxes and labels for the object as well as a box for entering the identifier that will be used to find the object.  You may decide which field you want to search on.  It would be helpful if it were one that was different for each object in the list, such as an ISBN number or borrower id.

After the user clicks the Add button, you probably should clear all the fields and tell the user to enter data for the new object.  Then after this is done, there should be some kind of Submit button.  You could also have a button to save the updated list back to the file.  That is optional.

Be careful of names for classes, methods and variables.  They should accurately describe what the object is supposed to do or represent.  For example, don’t call a book a person.  Your comments should now be longer and more explanatory.  Watch out for grammar and spelling errors.  They will not be caught by the compiler if they are in comments.

The example below should help you create a new window with buttons to go forward and back.  It creates one frame with a panel and a button.  The button shows a second frame.  It has a button that brings one back to the first frame.

import java.awt.event.*;
import java.awt.*;

/* ShowFrames is a frame with a button that shows a second frame.  The second frame has a button that when clicked will hide it. */
public class ShowFrames
{
     public static void main (String [] args)
     {
          FrameDemo frame = new FrameDemo ();
          frame.addWindowListener (new WindowCloser ());
          frame.show ();
     }
} // class ShowFrames

class WindowCloser extends WindowAdapter
{
     public void windowClosing (WindowEvent e) {System.exit (0);}
} // class WindowCloser

/* FrameDemo defines the first frame.  It creates a panel with a button.  When clicked, the button shows the second frame. */

class FrameDemo extends Frame
{
     private Panel panel;
     private Button showSecond;
     private SecondFrame secondFrame;
 
     FrameDemo ()
     {
          super ("Frame Demonstration");
          setSize (300, 300);
          panel = new Panel ();
          panel.setBackground (Color.cyan);

          showSecond = new Button ("Show Frame");
          showSecond.addActionListener (new ShowSecondListener ());
          panel.add (showSecond);

          add (panel);
          secondFrame = new SecondFrame ();
     } // constructor
 
     class ShowSecondListener implements ActionListener
     {
          public void actionPerformed (ActionEvent e) {secondFrame.show ();}
     } // inner class ShowSecondListener
} // class FrameDemo

/* The SecondFrame creates another frame.  It has a button that is used to hide the frame and so return to the first frame. */
class SecondFrame extends Frame
{
     private Panel panel;
     private Button hideFrame;
 
     SecondFrame ()
     {
          super ("Second Frame");
          setSize (100, 300);
          panel = new Panel ();
          hideFrame = new Button ("Hide");
          hideFrame.addActionListener (new HideListener ());
          panel.add (hideFrame);
          add (panel);
     } // constructor
 
     class HideListener implements ActionListener
     {
          public void actionPerformed (ActionEvent e) {hide ();}
     } // inner class HideListener
} // class SecondFrame