| | |
how to output the result in jframe
![]() |
•
•
Join Date: Mar 2009
Posts: 18
Reputation:
Solved Threads: 0
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 : )
Java Syntax (Toggle Plain Text)
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))); } }
0
#2 25 Days Ago
So use a JTextArea, then, instead of using System.out.print or println, you use the JTextAreas append.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
Similar Threads
- Count from multiple tables and group output by date (MySQL)
- getting the output of a terminal as input into a java program. (Java)
- not getting the proper output (JSP)
- Formatting output in c++ (C++)
- i need help with my output. (C++)
- How to show output with my condition from table with vb.net (ASP.NET)
- wierd gui/constructor problem (Java)
- Help with displaying text through GUI interface (Java)
- Dr.Python: running same output again (Python)
Other Threads in the Java Forum
- Previous Thread: Can you use Strings as 'values' in a hashtable?
- Next Thread: WTF!!! Vigenère Ciphering
| Thread Tools | Search this Thread |
6 @param actuate android api applet application arc array arrays automation balls binary bluetooth bold business byte c++ chat class client code codesnippet collections compare component coordinates database defaultmethod detection doctype dragging ebook eclipse educational error file fractal froglogic game givemetehcodez graphics gui guitesting helpwithhomework hql html ide ideas image ingres input integer internet intersect invokingapacheantprogrammatically j2me java javaexcel javaprojects jni jpanel jtextarea julia linux list map method methods mobile mysql netbeans newbie nextline parameter php pong problem program programming project recursion recursive scanner sell server set sms sort sql string sun swing swt terminal threads tree web websites windows






