Here I am again! I am working on the program below that is calculating payroll but am kind of lost on how to program the reset button after the net pay has been calculated. Any and all help would be greatly appreciated. Thanks.

import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class PayrollProgram extends JFrame

{
   //public static void main(String[] args) throws FileNotFoundException
   
   private JLabel fnameL, lnameL, hoursL, hrateL, idL, weeknumL, netPayL; 
	//left column of GUI component for field names

   private JTextField fnameTF, lnameTF, hoursTF, hrateTF, idTF, weeknumTF, netPayTF;
	//right column of GUI component for entering information in the fields

   private JButton calculateB, resetB, addB, exitB; //Buttons listed on GUI component

   private CalculateButtonHandler cbHandler;
	private ResetButtonHandler rbHandler;
	private AddButtonHandler abHandler;
   private ExitButtonHandler ebHandler;
	//methods objects for submit buttons on GUI

   private static final int WIDTH = 400;
   private static final int HEIGHT = 300;
	//height and width of GUI component

   public PayrollProgram()
   {
             //Create the seven labels, right justified
      fnameL = new JLabel("Enter First Name: ",SwingConstants.RIGHT);
      lnameL = new JLabel("Enter Last Name: ",SwingConstants.RIGHT);
      hoursL = new JLabel("Enter Hours Worked: ", SwingConstants.RIGHT);
      hrateL = new JLabel("Enter Hourly Rate: ", SwingConstants.RIGHT);
      idL = new JLabel("Enter Employee ID: ", SwingConstants.RIGHT);
      weeknumL = new JLabel("Enter Week Number: ", SwingConstants.RIGHT);
      netPayL = new JLabel("Calculated Net Pay: ", SwingConstants.RIGHT);

             //Create the seven text fields, ten characters in length
      fnameTF = new JTextField(10);
      lnameTF = new JTextField(10);
      hoursTF = new JTextField(10);
      hrateTF = new JTextField(10);
      idTF = new JTextField(10);
      weeknumTF = new JTextField(10);
      netPayTF = new JTextField(10);

             //Create Calculate Button to determine and show calculated net pay
      calculateB = new JButton("Calculate");
      cbHandler = new CalculateButtonHandler();
      calculateB.addActionListener(cbHandler);
		
				//Create Reset Button to clear text in field and re-enter information
		resetB = new JButton("Reset");
		rbHandler = new ResetButtonHandler();
		resetB.addActionListener(rbHandler);
		
				//Create Add to File Button which will print all informatio to a file
		addB = new JButton("Add to File");
		abHandler = new AddButtonHandler();
		addB.addActionListener(abHandler);

             //Create Exit Button closes the GUI screen when complete
      exitB = new JButton("Exit");
      ebHandler = new ExitButtonHandler();
      exitB.addActionListener(ebHandler);

             //Set the title of the window
      setTitle("Calculate a Pay Check");

             //Get the container
      Container pane = getContentPane();

             //Set the layout of rows and columns
      pane.setLayout(new GridLayout(9, 2));

             //Place the components in the pane
      pane.add(fnameL);
      pane.add(fnameTF);
      pane.add(lnameL);
      pane.add(lnameTF);
      pane.add(hoursL);
      pane.add(hoursTF);
      pane.add(hrateL);
      pane.add(hrateTF);
      pane.add(idL);
      pane.add(idTF);
      pane.add(weeknumL);
      pane.add(weeknumTF);
      pane.add(netPayL);
      pane.add(netPayTF);
      pane.add(calculateB);
		pane.add(addB);
		pane.add(resetB);
      pane.add(exitB);

             //Set the size of the window and display it
      setSize(WIDTH, HEIGHT);
      setVisible(true);
      setDefaultCloseOperation(EXIT_ON_CLOSE);
   }

   private class CalculateButtonHandler implements ActionListener
   {
      public void actionPerformed(ActionEvent e)
      {
        double hours, rate, netPay;
		//calculate pay and display in caluculated net pay
         hours = Double.parseDouble(hoursTF.getText());
         rate = Double.parseDouble(hrateTF.getText());
         netPay = hours * rate;
         
         netPayTF.setText("" + netPay);
      }
   }
	private class ResetButtonHandler implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
		//add reset button code
		}
	}
	//Add to File code
	private class AddButtonHandler implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
		// Stream to write file
		FileOutputStream fout;		

		try
			{
    // Open an output stream
    fout = new FileOutputStream ("myfile.txt");

    // Print a line of text
    new PrintStream(fout).println ("hello world!" + fnameTF.getText());

    // Close the output stream
    fout.close();		
		}
		catch (IOException f)
		{
   	 System.err.println ("Unable to write to file");
   	 System.exit(-1);
		}

		}
	}

   private class ExitButtonHandler implements ActionListener
   {
       public void actionPerformed(ActionEvent e)
       {
           System.exit(0);
       }
   }

   public static void main(String[] args) throws FileNotFoundException
   {
	    PayrollProgram rectObject = new PayrollProgram();
		
   }

}

Looks to me like you just want to set the text of your text fields back to zero or empty. You can just call setText(String) on each of them.

Thanks but I fixed that problem. Have another one if you want to help me out with it. I have it posted under Java Payroll Program. Just listed a couple of minutes ago. Thanks.

Be a part of the DaniWeb community

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