PDA

View Full Version : i need help in coding of payroll program


nemani_swathi
01-22-2009, 07:41 PM
I attached my Pay.java program here. I clear all errors but it doesn't display the Salary. Can you please correct my code.


import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.lang.Object;
import javax.swing.*;

public class Pay extends Applet implements ActionListener
{
Label label1,label2,payLabel ;
TextField input1,input2,pay;
float hourlyrate,hoursworked,salary;

// setup the graphical user interface components and initialize variables

public void init()
{
label1= new Label(" Enter the Hourly rate:");
add(label1);

input1=new TextField(10);
add(input1);

label2= new Label(" Enter the HoursWorked:");
add(label2);

input2=new TextField(10);
add(input2);

//payLabel= new Label(" The Salary is:");
//pay=new TextField(10);
//pay.setEdittable(false);
//add(payLabel);
}

public void actionPerformed(ActionEvent e)
{
float hourlyrate= Integer.parseInt(input1.getText());
float hoursworked= Integer.parseInt(input2.getText());

salary = (float) hourlyrate * hoursworked;
//pay.setText( String.format("%3.2f", salary) );
System.out.printf("salary:" + salary);
//System.out.printf( "'s weekly pay is: $%,.2fdollars\n", salary);
}
}

shyam
01-23-2009, 03:03 PM
when exactly should the calculation get invoked? you haven't attached an action listener to any of your components?