java.java
07-28-2008, 11:42 AM
Hi I have designed a payroll program- for my college project but i am unable to run the program, Please help me checking the error, if you find any error please redesign it please i will be very thankful to you
1. import javax.swing.*;
2. import java.awt.*;
3. import java.awt.event.*;
4.
5. public class payroll extends JFrame
6. {
7.
8.
9. private JLabel daysL,rateL,gpayL,deductionsL,taxL,sssL,cashadvL,totaldL,netpayL;
10. private JTextField daysTF,rateTF,gpayTF,taxTF,sssTF,cashadvTF,deductionTF,totaldTF,netpayTF;
11. private JButton calculateB, exitB;
12.
13. private CalculateButtonHandler cbHandler;
14. private ExitButtonHandler ebHandler;
15.
16.
17. private static final int WIDTH=400;
18. private static final int HEIGHT=500;
19.
20. public payroll()
21. {
22.
23. daysL=new JLabel("Number of days Worked",SwingConstants.RIGHT);
24. rateL=new JLabel("Rate Per Day",SwingConstants.RIGHT);
25. gpayL=new JLabel("Gross Pay",SwingConstants.RIGHT);
26. taxL=new JLabel("With Tax(10%)",SwingConstants.RIGHT);
27. sssL=new JLabel("SSS (8%)",SwingConstants.RIGHT);
28. cashadvL=new JLabel("Cash Advance:",SwingConstants.RIGHT);
29. totaldL=new JLabel("Total Deduction:",SwingConstants.RIGHT);
30. netpayL=new JLabel("Total Net Pay",SwingConstants.RIGHT);
31.
32. daysTF=new JTextField(10);
33. rateTF=new JTextField(10);
34. gpayTF=new JTextField(10);
35. taxTF=new JTextField(10);
36. sssTF=new JTextField(10);
37. cashadvTF=new JTextField(10);
38. totaldTF=new JTextField(10);
39. netpayTF=new JTextField(10);
40. calculateB=new JButton("Calculate");
41. cbHandler=new CalculateButtonHandler();
42.
43. calculateB.addActionListener(cbHandler);
44. exitB=new JButton("Exit");
45. ebHandler=new ExitButtonHandler();
46. exitB.addActionListener(ebHandler);
47.
48.
49.
50. setTitle("7'11 Payroll");
51.
52.
53. Container pane=getContentPane();
54.
55.
56. pane.setLayout(new GridLayout(9,2));
57.
58.
59. pane.add(daysL);
60. pane.add(daysTF);
61. pane.add(rateL);
62. pane.add(rateTF);
63. pane.add(gpayL);
64. pane.add(gpayTF);
65. pane.add(taxL);
66. pane.add(taxTF);
67. pane.add(sssL);
68. pane.add(sssTF);
69. pane.add(cashadvL);
70. pane.add(cashadvTF);
71. pane.add(totaldL);
72. pane.add(totaldTF);
73. pane.add(netpayL);
74. pane.add(netpayTF);
75. pane.add(calculateB);
76. pane.add(exitB);
77.
78. setSize(WIDTH, HEIGHT);
79. setVisible(true);
80. setDefaultCloseOperation(EXIT_ON_CLOSE);
81.
82. }
83. public class CalculateButtonHandler implements ActionListener
84. {
85. public void actionPerformed(ActionEvent e)
86. {
87.
88. double days,rate,gpay,tax,sss,totald,cashadv,netpay;
89. days=Double.parseDouble(daysTF.getText());
90. rate=Double.parseDouble(rateTF.getText());
91. gpay=Double.parseDouble(gpayTF.getText());
92. tax=Double.parseDouble(taxTF.getText());
93. sss=Double.parseDouble(sssTF.getText());
94. totald=Double.parseDouble(totaldTF.getText());
95. netpay=Double.parseDouble(netpayTF.getText());
96. cashadv=Double.parseDouble(cashadvTF.getText());
97.
98. gpay=(days*rate);
99. tax=(gpay*.10);
100. sss=(tax*.08);
101. totald=(tax+sss)+cashadv;
102. netpay=(gpay-totald);
103.
104.
105.
106. }
107. }
108.
109. private class ExitButtonHandler implements ActionListener
110. {
111. public void actionPerformed(ActionEvent e)
112. {
113. System.exit(0);
114. }
115. }
116.
117. public static void main (String [] args)
118. {
119. payroll recObject= new payroll();
120. }
121. }
1. import javax.swing.*;
2. import java.awt.*;
3. import java.awt.event.*;
4.
5. public class payroll extends JFrame
6. {
7.
8.
9. private JLabel daysL,rateL,gpayL,deductionsL,taxL,sssL,cashadvL,totaldL,netpayL;
10. private JTextField daysTF,rateTF,gpayTF,taxTF,sssTF,cashadvTF,deductionTF,totaldTF,netpayTF;
11. private JButton calculateB, exitB;
12.
13. private CalculateButtonHandler cbHandler;
14. private ExitButtonHandler ebHandler;
15.
16.
17. private static final int WIDTH=400;
18. private static final int HEIGHT=500;
19.
20. public payroll()
21. {
22.
23. daysL=new JLabel("Number of days Worked",SwingConstants.RIGHT);
24. rateL=new JLabel("Rate Per Day",SwingConstants.RIGHT);
25. gpayL=new JLabel("Gross Pay",SwingConstants.RIGHT);
26. taxL=new JLabel("With Tax(10%)",SwingConstants.RIGHT);
27. sssL=new JLabel("SSS (8%)",SwingConstants.RIGHT);
28. cashadvL=new JLabel("Cash Advance:",SwingConstants.RIGHT);
29. totaldL=new JLabel("Total Deduction:",SwingConstants.RIGHT);
30. netpayL=new JLabel("Total Net Pay",SwingConstants.RIGHT);
31.
32. daysTF=new JTextField(10);
33. rateTF=new JTextField(10);
34. gpayTF=new JTextField(10);
35. taxTF=new JTextField(10);
36. sssTF=new JTextField(10);
37. cashadvTF=new JTextField(10);
38. totaldTF=new JTextField(10);
39. netpayTF=new JTextField(10);
40. calculateB=new JButton("Calculate");
41. cbHandler=new CalculateButtonHandler();
42.
43. calculateB.addActionListener(cbHandler);
44. exitB=new JButton("Exit");
45. ebHandler=new ExitButtonHandler();
46. exitB.addActionListener(ebHandler);
47.
48.
49.
50. setTitle("7'11 Payroll");
51.
52.
53. Container pane=getContentPane();
54.
55.
56. pane.setLayout(new GridLayout(9,2));
57.
58.
59. pane.add(daysL);
60. pane.add(daysTF);
61. pane.add(rateL);
62. pane.add(rateTF);
63. pane.add(gpayL);
64. pane.add(gpayTF);
65. pane.add(taxL);
66. pane.add(taxTF);
67. pane.add(sssL);
68. pane.add(sssTF);
69. pane.add(cashadvL);
70. pane.add(cashadvTF);
71. pane.add(totaldL);
72. pane.add(totaldTF);
73. pane.add(netpayL);
74. pane.add(netpayTF);
75. pane.add(calculateB);
76. pane.add(exitB);
77.
78. setSize(WIDTH, HEIGHT);
79. setVisible(true);
80. setDefaultCloseOperation(EXIT_ON_CLOSE);
81.
82. }
83. public class CalculateButtonHandler implements ActionListener
84. {
85. public void actionPerformed(ActionEvent e)
86. {
87.
88. double days,rate,gpay,tax,sss,totald,cashadv,netpay;
89. days=Double.parseDouble(daysTF.getText());
90. rate=Double.parseDouble(rateTF.getText());
91. gpay=Double.parseDouble(gpayTF.getText());
92. tax=Double.parseDouble(taxTF.getText());
93. sss=Double.parseDouble(sssTF.getText());
94. totald=Double.parseDouble(totaldTF.getText());
95. netpay=Double.parseDouble(netpayTF.getText());
96. cashadv=Double.parseDouble(cashadvTF.getText());
97.
98. gpay=(days*rate);
99. tax=(gpay*.10);
100. sss=(tax*.08);
101. totald=(tax+sss)+cashadv;
102. netpay=(gpay-totald);
103.
104.
105.
106. }
107. }
108.
109. private class ExitButtonHandler implements ActionListener
110. {
111. public void actionPerformed(ActionEvent e)
112. {
113. System.exit(0);
114. }
115. }
116.
117. public static void main (String [] args)
118. {
119. payroll recObject= new payroll();
120. }
121. }