                // Class to provide a GUI for the
                // Ship examples..
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
// import javax.swing.text.*;
import java.io.*;

    // The GUI consists of a two labelled TextAreas.
    // The upper area is use for the Bank to report to and
    // the lower is use for Accounts.
    // A Quit button is also provided.
class BankGUI extends JFrame {
    public BankGUI(){
        super("Simple Bank");
        setTitle("Simple Bank");
        setBackground(Color.white);

        final int textSize = 12;
        final Font textFont = new Font("Monospaced",Font.PLAIN,textSize);
        final Font labelFont = new Font("SansSerif",Font.BOLD,textSize+2);
        final Container contents = getContentPane();

        contents.setLayout(new GridBagLayout());

        GridBagConstraints constraints = new GridBagConstraints();
        // Common constraints.
        constraints.gridx = 0;
        constraints.weightx = 1;
        constraints.anchor = GridBagConstraints.CENTER;

        constraints.gridy = 0;
        // A label for the bank reporting area.
        constraints.weighty = 0;
        constraints.fill = GridBagConstraints.NONE;
        JLabel bankLabel = new JLabel("Account Details",JLabel.CENTER);
        bankLabel.setFont(labelFont);
        contents.add(bankLabel,constraints);

        constraints.gridy++;
        // Allow the bank area to take up some of the slack.
        constraints.weighty = 1;
        constraints.fill = GridBagConstraints.BOTH;
        bankReportingArea.setFont(textFont);
        bankReportingArea.setBackground(Color.white);
        contents.add(new JScrollPane(bankReportingArea,
                                     JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                     JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED),
                     constraints);

        constraints.gridy++;
        // A label for the account reporting area.
        constraints.weighty = 0;
        constraints.fill = GridBagConstraints.BOTH;
        JLabel accountLabel = new JLabel("Account Statements",JLabel.CENTER);
        accountLabel.setFont(labelFont);
        contents.add(accountLabel,constraints);

        constraints.gridy++;
        // Allow the account area to take up some of the slack.
        constraints.weighty = 2;
        constraints.fill = GridBagConstraints.BOTH;
        accountReportingArea.setFont(textFont);
        accountReportingArea.setBackground(Color.white);
        contents.add(new JScrollPane(accountReportingArea,
                                     JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                     JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED),
                     constraints);

        constraints.gridy++;
        // The Quit button.
        constraints.weighty = 0;
        JPanel buttonPanel = new QuitJPanel();
        contents.add(new QuitJPanel(),constraints);

        final int xPosition = 100, yPosition = 100;
        setLocation(xPosition,yPosition);
        pack();
        setVisible(true);
    }

    // Let this Bank use the GUI.
    public void add(SimpleBank b){
        // Get the bank to report into a text area.
        b.setWriter(getBankWriter());
        // Get the accounts to report into a text area.
        b.setAccountWriter(getAccountWriter());
    }

    protected PrintWriter getBankWriter(){
        return bankWriter;
    }

    protected PrintWriter getAccountWriter(){
        return accountWriter;
    }

    // Reports from the bank to be displayed in this area.
    private static final int bankReportingRows = 4, cols = 60;
    private JTextArea bankReportingArea = new JTextArea("",bankReportingRows,cols);
    // The PrintWriter associated with this area.
    private PrintWriter bankWriter =
            new TextComponentPrintWriter(bankReportingArea);

    // Reports from the accounts to be displayed in this area.
    private static final int accountReportingRows = 10;
    private final JTextArea accountReportingArea =
                            new JTextArea("",accountReportingRows,cols);
    // The PrintWriter associated with this area.
    private final PrintWriter accountWriter =
            new TextComponentPrintWriter(accountReportingArea);
}
