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
error.
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;
//Constructor
public FundraiserGUI() { //set title
super("Fundraiser Donor List");
//set window size
setSize(WINDOW_HEIGHT, WINDOW_WIDTH);
//this is for the close button
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Closes window
this.buildPanel();
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));
charityPanel.add(donorLastName);
charityPanel.add(donorLastNameTextField);
charityPanel.add(donorFirstName);
charityPanel.add(donorFirstNameTextField);
charityPanel.add(donorCharity);
charityPanel.add(donorCharityTextField);
charityPanel.add(charityDon);
charityPanel.add(charityDonTextField);
buttonPanel.setLayout(new GridLayout(1, 2));
buttonPanel.add(saveButton);
buttonPanel.add(exitButton);
//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 {
@Override
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 {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
public static void main(String[] args) {
FundraiserGUI fundraiserGUI;
fundraiserGUI = new FundraiserGUI();
}
}