Greetings, I am new to
java, I have been working on an
applet, which so far compiles and mostly works okay. The problem is the screen output after the calculation in the ActionPerformed Method, there is none showing. I am hoping some one will help point me in the right direction so I can figure out why. At this point, I have been working on this applet long enough that I think I am brain Dead. My code is below.
import javax.swing.*; //Must import both of these
import java.awt.*; //for every java applet
import java.awt.event.*; // for the event class,(ActionListener)
import java.applet.*; //Must import for extends Applet
import java.text.*;
/**
* Program for the CalcPay class.
*
* @author Larry Brink
* @version 11/18/2003
*/
public class CalcPay extends JApplet implements ActionListener
{
//need in every applet, the container contains eveything in the applet
Container con = getContentPane();
//creating label for enter hours
JLabel enterHours = new JLabel("Enter Hours Worked");
//creating label for enter rate
JLabel enterRate = new JLabel("Enter Hourly Rate");
Label seeStart = new Label("");
//creating label for gross pay
JLabel gross = new JLabel("");
//creating label for net pay
JLabel net = new JLabel("");
//creating label for withholding
JLabel holding = new JLabel("");
//creating Button for calculate pay
JButton calculatePay = new JButton("Calculate Pay");
//creating text field for entering hours worked
JTextField hoursWorked = new JTextField(2);
//creating text field for entering hourly rate
JTextField hourlyRate = new JTextField(5);
//Font myNewFont changes the Font, the "+" needs to be used to use both Italic and Bold
Font myFont = new Font ("Arial", Font.BOLD +Font.ITALIC, 14);
/**
* Description of the Method
*/
public void init() // initialize the Method
{
//setting the Container Layout, different way then used above
con.setLayout (new FlowLayout());
//setting the font style for the JLabels
enterHours.setFont (myFont);
enterRate.setFont (myFont);
calculatePay.setFont (myFont);
con.add (enterHours); //adds the JLabel enterHours
con.add (hoursWorked); //adds the JTextField hoursWorked
con.add (enterRate); //adds the JLabel enterRate
con.add (hourlyRate); //adds the JTextField hourlyRate
calculatePay.setForeground(Color.red);
calculatePay.setBackground(Color.blue);
con.add (calculatePay);//adds the JButton calculatePay
con.add(gross); //adds the JLabel gross pay
con.add(net); //adds the JLabel net pay
con.add(holding); //adds the JLabel withholding
calculatePay.addActionListener(this);
hoursWorked.requestFocus();
}
/**
* Description of the method
* param thisCalc Description of the parameter
*/
public void actionPerformed(ActionEvent thisCalc)
{
int[] income = {0, 100, 300, 600};
int[] withHolding = {10, 15, 21, 28};
int hours = Integer.parseInt(hoursWorked.getText ());
double rate = Double.parseDouble(hourlyRate.getText ());
int withHoldingAmount = 0;
double netPay = 0;
double grossPay = 0;
int x = income.length;
for (x = income.length; x >= 0; --x)
{
if (grossPay >= income [x])
{
withHoldingAmount = withHolding[x];
grossPay = hours * rate;
netPay = grossPay - withHoldingAmount;
x = 0;
}
}
gross.setText("Your gross pay is $ " + grossPay);
net.setText("Your net pay is $ " + netPay);
holding.setText("Your withholding is $ " + withHoldingAmount);
}
}
Please take it easy on me, I am new to this. Thanks in advanced for any and all help.
Larry