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();
		
		calculateB.addActionListener(cbHandler);
		exitB = new JButton("Exit");
		ebHandler = new ExitButtonHandler();
		exitB.addActionListener(ebHandler);
		
	
		
		setTitle("7'11 Payroll");
		
	
		Container pane=getContentPane();
		
	
		pane.setLayout(new GridLayout(9,2));

	
		pane.add(daysL);
		pane.add(daysTF);
		pane.add(rateL);
		pane.add(rateTF);
		pane.add(gpayL);
		pane.add(gpayTF);
		pane.add(taxL);
		pane.add(taxTF);
		pane.add(sssL);
		pane.add(sssTF);
		pane.add(cashadvL);
		pane.add(cashadvTF);
		pane.add(totaldL);
		pane.add(totaldTF);
		pane.add(netpayL);
		pane.add(netpayTF);
		pane.add(calculateB);
		pane.add(exitB);
		
		setSize(WIDTH, HEIGHT);
		setVisible(true);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		
}
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)
	{
		System.exit(0);
	}
}
}

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.

AARGH!

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

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 for hfx642

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.