This code outputs the result in console. I want to implement a Swing JFrame, producing output readable by user. Do I have to change all my code if I want to use JFrame? Can anyone help? I am not familiar with JFrame at all. Thanks : )

import javax.swing.*;

/**
 * Process payroll.

 */
public class payroll 
{
    /**
     * Creates an array of employees (currently hard coded), and asks
     * for the hours of each, then prints paystubs for each and total
     * amount paid at the end.
     */
		
    public static void main(String[] args)
    {	 
    	
    	
    	
    	    	
		Employee[] emp = new Employee[5];
		emp[0] = new HourlyEmployee("Glenn, James", "123456789", 6.00);
		emp[1] = new HourlyEmployee("Eastman, Roger", "222222222", 8.00);
		emp[2] = new SalariedEmployee("Haddad, David", "823712468", 150000);
		emp[3] = new SalariedEmployee("Buckley, James", "284618461", 125000);
		emp[4] = new SalariedEmployee("Thomas, Amanda", "184649714", 110000);

		
		// do this for two weeks
	
		for (int wk = 0; wk < 2; wk++)
		    {
			double totalPaid = 0.0;
	
			// go over all employees
	
			for (int e = 0; e < emp.length; e++)
			    {
				double hrs = Double.parseDouble(JOptionPane.showInputDialog("Enter hours worked during week " + (wk + 1) + " for " + emp[e]));
	
				totalPaid += emp[e].calcWeeklyPay(hrs);
				System.out.println(emp[e].makePaystub(hrs)); 
					
				emp[e].updateRecord(hrs);
				
				
			    }
			
			System.out.println("Total paid for week = " + totalPaid);
		    }
		
	    	System.exit(0);
    }
}

public class Employee
{
  
    private String ssn;
    private String name;   
    private double ytdPay;

    public Employee(String n, String s)
    {
	name = n;
	ssn = s;
	ytdPay = 0;
    }    
    public double getYTDPay()
    {
	return ytdPay;
    }   
    public double calcWeeklyPay(double hrs)
    {
	return 0.0;
    }

     public void updateRecord(double hrs)
    {
	ytdPay += calcWeeklyPay(hrs);
    }

     public String toString()
    {
	return (ssn.substring(0, 3) + "-"
 		+ ssn.substring(3, 5) + "-" 
		+ ssn.substring(5, 9) + " "
		+ name);
    }   
    public String makePaystub(double hrs)
    {
	return "";
    }
}

public class HourlyEmployee extends Employee 
{
      private double wage;

        public HourlyEmployee(String n, String s, double w)
    {
	super(n, s);

	wage = w;
    }
   
    public double calcWeeklyPay(double hrs)
    {
	return wage * hrs;
    }   
    public String makePaystub(double hrs)
    {
	return (toString() + " " + hrs + " 0 " + wage + " "
		+ calcWeeklyPay(hrs) + " "
		+ (getYTDPay() + calcWeeklyPay(hrs)));
    }
}

public class SalariedEmployee extends Employee
{
     private double salary;
     private double leave;

     public SalariedEmployee(String n, String s, double sal)
    {
	super(n, s);

	salary = sal;
	leave = 0.0;
    }

     public double calcWeeklyPay(double hrs)
    {
	double weeklySalary = salary / (365.0 / 7);

	return weeklySalary * Math.min(40.0, hrs + calcLeaveUsed(hrs)) / 40.0;
    }

    public double calcLeaveUsed(double hrs)
    {
	if (hrs > 40.0)
	    return 0; // worked full week; no leave used
	else
	    return Math.min(leave, 40.0 - hrs);
    }

     public void updateRecord(double hrs)
    {
	// update year to date pay

	super.updateRecord(hrs);

	// take out any leave used

	double leaveUsed = calcLeaveUsed(hrs);
	leave -= leaveUsed;

	// put back in leave earned (leave earned if paid for >= 40 hrs)

	if (hrs + leaveUsed >= 40.0)
	    leave += 4;
    }
     public String makePaystub(double hrs)
    {
	return (toString() + " " + hrs + " " + calcLeaveUsed(hrs) + " "
		+ salary + " " + calcWeeklyPay(hrs) + " "
		+ (getYTDPay() + calcWeeklyPay(hrs)));
    }
}

So use a JTextArea, then, instead of using System.out.print or println, you use the JTextAreas append.

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.