Computer Science 122
Assignment 5
Due: October 12, 2004

For this program, you should have one frame with two buttons.  The first button should display all the books in the library database and the second should show all the borrowers.  The data should be displayed in a TextArea on the frame.

Follow the method in the Insurance Policies example.  You do not have to use inheritance here.  Instead, follow the example of the frame.

// InsurancePolicies displays two different tables from the same database in the same text area.

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

public class PolicyFrame extends Frame
{
     private Panel panel;
     private Label areaLabel;
     private TextArea area;
     private Button displayCar, displayLife;
     private Policies policies;
     private Connection con;
 
     public PolicyFrame ()
     {
          super ("Frame");
          setSize (300, 300);
 
          // Add a window closer to the frame.
          addWindowListener (new WindowAdapter()
               {public void windowClosing(WindowEvent e) {System.exit(0);}});
 
          // Get a new panel and set its background color.
          panel = new Panel ();
          panel.setBackground (Color.cyan);
 
          // Get a text area and add it to the panel.
          areaLabel = new Label ("Insurance");
          area = new TextArea (10, 30);
 
          // Get a new button and add an action listener to it.
          displayCar = new Button ("Display Car Policies");
          displayCar.addActionListener (new DisplayCarListener ());
 
          // Get a new button and add an action listener to it.
          displayLife = new Button ("Display Life Policies");
          displayLife.addActionListener (new DisplayLifeListener ());
 
          panel.add (areaLabel); panel.add (area);
          panel.add (displayCar); panel.add (displayLife);
          add (panel);
 
          try
          {
               Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
               con = DriverManager.getConnection ("jdbc:odbc:insurance");
               policies = new Policies ();
          } catch (ClassNotFoundException e){System.out.println ("Database connection exception.");}
            catch (SQLException e) {System.out.println ("SQL Exception");}
     } // constructor

     // An inner class that displays the library data when the button is clicked.
     class DisplayCarListener implements ActionListener
     {
          public void actionPerformed (ActionEvent e)
          {
               try
               {
                    // Display the data on the text area.
                    policies.displayCarPolicies (con, area);
               } catch (SQLException ex) {System.out.println ("SQL Exception");}
          } // actionPerformed
     } // DisplayCarListener

      // An inner class that displays the library data when the button is clicked.
     class DisplayLifeListener implements ActionListener
     {
          public void actionPerformed (ActionEvent e)
          {
               try
               {
                    // Display the data on the text area.
                    policies.displayLifePolicies (con, area);
               } catch (SQLException ex) {System.out.println ("SQL Exception");}
          } // actionPerformed
     } // DisplayLifeListener
 
     // The main method gets a new frame and shows it.
     public static void main (String [] args)
     {
          PolicyFrame frame = new PolicyFrame ();
          frame.setVisible (true);
     }
} // class PolicyFrame

Add in more classes that display the two databases.