Looking for Java help! I am working on the payroll program below and would like some help please. When I run the prograom, I am using jGrasp, the program runs with no errors identified in the code but I get the following window that pops up...."No main methods, applets, or MIDlets found in file. What do I need to do please help.

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

public class payroll extends JFrame

	private JLabel daysL,rateL,gpayL,deductionsL,taxL,sssL,cashadvL,totaldL,netpayL;
	private JTextField daysTF,rateTF,gpayTF,taxTF,sssTF,cashadvTF,deductionTF,totaldTF,netpayTF;
	private JButton calculateB, exitB;
	private CalculateButtonHandler cbHandler;
	private ExitButtonHandler ebHandler;

	private static final int WIDTH=400;
	private static final int HEIGHT=500;
	public payroll()
		daysL = new JLabel("Number of days Worked",SwingConstants.RIGHT);
		rateL = new JLabel("Rate Per Day",SwingConstants.RIGHT);
		gpayL = new JLabel("Gross Pay",SwingConstants.RIGHT);
		taxL = new JLabel("With Tax(10%)",SwingConstants.RIGHT);
		sssL = new JLabel("SSS (8%)",SwingConstants.RIGHT);
		cashadvL = new JLabel("Cash Advance:",SwingConstants.RIGHT);
		totaldL = new JLabel("Total Deduction:",SwingConstants.RIGHT);
		netpayL = new JLabel("Total Net Pay",SwingConstants.RIGHT);
		daysTF = new JTextField(10);
		rateTF = new JTextField(10);
		gpayTF = new JTextField(10);
		taxTF = new JTextField(10);
		sssTF = new JTextField(10);
		cashadvTF = new JTextField(10);
		totaldTF = new JTextField(10);
		netpayTF = new JTextField(10);
		calculateB = new JButton("Calculate");
		cbHandler = new CalculateButtonHandler();
		exitB = new JButton("Exit");
		ebHandler = new ExitButtonHandler();
		setTitle("7'11 Payroll");
		Container pane=getContentPane();
		pane.setLayout(new GridLayout(9,2));

		setSize(WIDTH, HEIGHT);
public class CalculateButtonHandler implements ActionListener
	public void actionPerformed(ActionEvent e)

		double days,rate,gpay,tax,sss,totald,cashadv,netpay;
		days = Double.parseDouble(daysTF.getText());
		rate = Double.parseDouble(rateTF.getText());
		gpay = Double.parseDouble(gpayTF.getText());
		tax = Double.parseDouble(taxTF.getText());
		sss = Double.parseDouble(sssTF.getText());
		totald = Double.parseDouble(totaldTF.getText());
		netpay = Double.parseDouble(netpayTF.getText());
		cashadv = Double.parseDouble(cashadvTF.getText());
		gpay = (days*rate);
		tax = (gpay*.10);
		sss = (tax*.08);
		totald =(tax+sss)+cashadv;
		netpay =(gpay-totald);

private class ExitButtonHandler implements ActionListener
	public void actionPerformed(ActionEvent e)

Recommended Answers

Every Java program must have a "main" method that looks like this:

public static void main(String[] args) {
  // your startup code goes here

(similar but different standard methods are required to start an applet)

When you try to run your program Java looks for …

Jump to Post

Java is case sensitive. payroll is not the same as Payroll

Jump to Post

All 5 Replies

Every Java program must have a "main" method that looks like this:

public static void main(String[] args) {
  // your startup code goes here

(similar but different standard methods are required to start an applet)

When you try to run your program Java looks for that method and calls it to get your code started.

Thanks! I added the following and am now getting the following errors. Please know I am new to Java and really appreciate your help.

public static void main(String[] args)
payroll recObject = new payroll();

This is what is being generated with the errors...

----jGRASP exec: java Payroll

java.lang.NoClassDefFoundError: Payroll (wrong name: payroll)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: Payroll.  Program will exit.
Exception in thread "main"
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.


Thanks. that got me thinking the class file that was created earlier was Payroll fixed it and was able to see GUI with input fields but calculations are not working at all any ideas?

Member Avatar

How do you know that your calculations are not working?
I don't really see where you are displaying your calculated results.

Be a part of the DaniWeb community

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