pekemp23 0 Newbie Poster

Assignment is as follows:

**Create a GUI-based program to accept name of donor, name of charity, and amount of pledge from the user.
Display a list of entries in a JTextArea or JTable.
Submit the .java source file or files for this program. Do not use any package statements in your programs. Code created with a GUI generator will not be accepted. **

It compiles and runs fine. Teacher has asked that the following things be fixed. Struggling on getting these things around and fixed. Very green on this stuff.

1) You need to add the parts to the JFrame and not a JPanel

2) In the main(), you need to call the buildPanel() method.

This is done - 3) I would add a layout manager. I just did a GridLayout. I would get rid of the FundraiserGUI panel (by the way, this is bad form to name a panel the same as the class. It should be something different and start with a lower case letter) I would create 2 new panels, one for the buttons, and one for the info (name label, name text, etc). Set a layout manager to each panel. GridLayout(4, 2) for info, GridLayout(1, 2) for buttons (its rows, columns)

So is this - 4) Set a BorderLayout for the JFrame.

5) You need to shorten the labels,

6) maybe add a label to the bottom,

7) remove the package statement.

8) Also, the text field does not append correctly.

 * Patrick Kemp, Daniel Dodd, and
 * PRG/421 Java 2
 * Unitiveristy of Phoenix
 * 02/15/14 

package fundraisergui;
 * @author Patrick Kemp, Daniel Dodd, and
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 FundraiserGUI;
    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  
       //FundraiserGUI = new JPanel();  
        charityPanel = new JPanel();
        buttonPanel = new JPanel ();

        // add everything to new charityPanel in succession  
        // But first, add a layout manager to the JPanel
        charityPanel.setLayout(new GridLayout(4,2));
        charityPanel.add(donorCharityTextField );  

        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  
            //double donation = Integer.parseInt(charityDon);  
            double donation = Double.parseDouble(charityDon);  

            // TextArea data to be displayed  

    // 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();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.