My teamate and i are looking into how to:

The application did not work as required. There was a package statement; (-2)
Even though you caught the exception, the incorrect donation should not be
printed out to the JtextArea. (-2) I would also work on appending to the
text area and displaying a pop-up window to let the user know about the input
The code was nicely documented, but did not include a description of what the
class did in the prolog. (-1) Please remove all commented out code. (-1)
This is a good first start for your final application. Nice try!

Also we need to:

Modify the program you created in Week Three to write the data—name, amount, and charity—into a sequential data file.

Implement a capability of reading what is in the existing data file and displaying it in the text area.

Submit the .java source file or files for the program. Do not use any package statements in your programs. Code created with a GUI generator will not be accepted.

package fundraisergui;

 * @author  
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; // Event listener
import java.text.NumberFormat;
import javax.swing.*;       // GUI building 

public class FundraiserGUI extends JFrame {

    // Gui dimensions
    private JPanel charityPanel;
    private final int WINDOW_HEIGHT = 525;
    private final int WINDOW_WIDTH = 800;
    // declare Labels   
    private JLabel donorLastName;   // Last name of donor
    private JLabel donorFirstName;  //First name of donor
    private JLabel donorCharity;    // Charity to be donated too
    private JLabel charityDon;      //Donation amount
// declare TextFields for user input  
    private JTextField donorLastNameTextField;
    private JTextField donorFirstNameTextField;
    private JTextField donorCharityTextField;
    private JTextField charityDonTextField;
// declare Buttons & TextArea  
    private JButton saveButton;
    private JButton exitButton;
    private JTextArea donorList;
    private JPanel buttonPanel;

    public FundraiserGUI() {            //set title
        super("Fundraiser Donor List");

        //set window size

        //this is for the close button
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  //Closes window

        setVisible(true);   // this will enable the gui to be seen

    private void buildPanel() {

        // below are the fields requesting entry & text entry fields for end  
        // user input  
        donorLastName = new JLabel("Enter last name: ");
        donorFirstName = new JLabel("Enter first name: ");
        donorCharity = new JLabel("Name of charity: ");
        charityDon = new JLabel("Charity amount: ");
        donorLastNameTextField = new JTextField(25);
        donorFirstNameTextField = new JTextField(15);
        donorCharityTextField = new JTextField(75);
        charityDonTextField = new JTextField(10);

        // below are the save & exit buttons  
        saveButton = new JButton("Save");
        exitButton = new JButton("Exit");

        // below is the TextArea for the pledger list  
        donorList = new JTextArea(25, 75);

        // required action listeners for button functionality  
        saveButton.addActionListener(new saveButtonListener());
        exitButton.addActionListener(new exitButtonListener());

        // panel creation  
        charityPanel = new JPanel();
        buttonPanel = new JPanel();

        // add everything to new charityPanel in succession  

        charityPanel.setLayout(new GridLayout(4, 2));

        buttonPanel.setLayout(new GridLayout(1, 2));

        //Add layout manager to JFrame
        this.setLayout(new BorderLayout());
        //Location of the panel
        this.add(charityPanel, BorderLayout.NORTH);
        this.add(donorList, BorderLayout.CENTER);
        this.add(buttonPanel, BorderLayout.SOUTH);

    // establish hidden class for save button Listener class listed above  
    // in the panel build  
    private class saveButtonListener implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            // assign data to file... this will not work until Wk4 when we  
            // create a separate database file  
            NumberFormat numbers = NumberFormat.getCurrencyInstance();

            // declare strings for database  
            String donorLastName;
            String donorFirstName;
            String donorCharity;
            String charityDon;  // 

            // required 'get' methods for Strings  
            donorLastName = donorLastNameTextField.getText();
            donorFirstName = donorFirstNameTextField.getText();
            donorCharity = donorCharityTextField.getText();
            charityDon = charityDonTextField.getText();

            // required conversion of pledge amount from text to integers  
            try {
                double donation = Double.parseDouble(charityDon);
            catch (NumberFormatException ex) {

                System.out.println("There was an error in the donation box.");


            donorList.setText(donorLastName + "     " + donorFirstName + "    " + donorCharity + "    " + charityDon);

    // establish hidden class for exit button Listener class listed above  
    // in the panel build  
    private class exitButtonListener implements ActionListener {

        public void actionPerformed(ActionEvent e) {

    public static void main(String[] args) {
        FundraiserGUI fundraiserGUI;
        fundraiserGUI = new FundraiserGUI();

Delete line 7 which is your package statement.

Try something like the following for your exception (line 133-137):

            catch (NumberFormatException ex) {

                System.out.println("There was an error in the donation box.");

                if (charityDon.contains("$"))
                    javax.swing.JOptionPane.showMessageDialog(null,  "'Charity amount' contains non-numeric characters. Please enter a valid monetary value (do not use '$')." );  
                    javax.swing.JOptionPane.showMessageDialog(null,  "'Charity amount' contains non-numeric characters. Please enter a valid monetary value." );  


I would also change your code to the following:

    private final int WINDOW_HEIGHT = 225;
    private final int WINDOW_WIDTH = 400;


because when I ran it, the form was larger than needed.

This article has been dead for over six months. Start a new discussion instead.