Computer Science 122
Assignment 8
Due: April 16, 2002

Now change your applet into a frame.  You can use the following code:

// Main class that instantiates the frame.
public class OrderFrame
{
     public static void main (String [] args)
     {
          OrderWindow frame = new OrderWindow ();
          frame.addWindowListener (new WindowCloser ());
          frame.show ();
     } // main method
} // class ShowFrames

// class to activate the closing icon on the frame.
class WindowCloser extends WindowAdapter
{
     public void windowClosing (WindowEvent e){System.exit (0);}
} // class WindowCloser

// class that creates a frame with a panel, text area, and three buttons.  It also instantiates the list.
class OrderWindow extends Frame
{
     /* Code similar to that in your applet.  However, the init method becomes the constructor.  See the entire example on the website under Order Example with a Frame and a Saved Method. */
} // class OrderWindow

You should also add a new button that when clicked will save the linked list to an output file.  This file should contain all the data in a format suitable for printing out.  This gives you a way of capturing a program’s output.  The following methods should help:

// Method that saves the list of orders to a second file.
 public void saveOrders ()
 {
     try
    {
           PrintStream outfile = new PrintStream (new FileOutputStream ("orderFile2.txt"));
           Order tempOrder = listHead;
           while (tempOrder != null)
           {
                tempOrder.outputOrder (outfile);
                tempOrder = tempOrder.getNext ();
           }
           outfile.close ();
      } catch (FileNotFoundException e) {System.out.println ("No File");}
 } // method saveOrders

 // Method to print the order to an output file.
 public void outputOrder (PrintStream outfile)
 {
      outfile.println ("Product Name: " + name);
      outfile.println ("Product ID: " + id);
      outfile.println ("Price: " + price);
      outfile.println ("Quantity: " + quantity);
      outfile.println ();
 } // method outputOrder