Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2009
    Location
    Dayton, OHIO
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    i need help in coding of payroll program

    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);
    }
    }

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    when exactly should the calculation get invoked? you haven't attached an action listener to any of your components?
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •