Stephanie,
Here is my java code:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
public class Calculate extends Applet implements ActionListener
{
//create label for hours input field
Label hoursWorked = new Label("Enter hours worked");
//create input fields
TextField hours = new TextField("",3);
//create label for rate of pay input field
Label hourRate = new Label("Enter hourly rate of pay");
//create input fields
TextField rate = new TextField("",7);
//create label for calculated gross pay
Label grossPay = new Label("Gross Pay");
//create input fields
TextField gross = new TextField("",7);
//create label for calculated net pay
Label netPay = new Label("Net Pay");
//create input fields
TextField net = new TextField("",7);
//Create a button
Button pay = new Button("Click to calculate pay");
//Create the font
Font myNewFont = new Font("Courier",Font.BOLD,12);
//format for answer
DecimalFormat df = new DecimalFormat("$###,###,##0.00");
public void init()
{
hoursWorked.setFont(myNewFont);
add(hoursWorked);
add(hours);
hourRate.setFont(myNewFont);
add(hourRate);
add(rate);
grossPay.setFont(myNewFont);
add(grossPay);
gross.setEditable(false);
add(gross);
netPay.setFont(myNewFont);
add(netPay);
net.setEditable(false);
add(net);
pay.setFont(myNewFont);
add(pay);
pay.addActionListener(this);
//add focus listener
hours.addFocusListener(new MyFocusAdapter());
hours.requestFocus();
}
public void actionPerformed(ActionEvent thisEvent)
{
//figure gross pay
double hrs;
double rt;
double ansGross;
String ansString;
String ansString2;
hrs = Double.parseDouble((hours.getText()));
rt = Double.parseDouble((rate.getText()));
ansGross = hrs * rt;
//figure net income
double[] income = {0, 100.00, 300.00, 600.00};
double[] withHold = {.10,.15,.21,.28};
double wh;
boolean found = false;
double ansNet;
int sub = 3;
while(sub >0 && ansGross<income[sub])
--sub;
wh = withHold[sub];
found = true;
ansNet = (ansGross - (ansGross * wh));
ansString = df.format(ansGross);
gross.setText("" + ansString);
ansString2 = df.format(ansNet);
net.setText("" + ansString2);
invalidate();
validate();
}
class MyFocusAdapter extends FocusAdapter
{
public void focusGained(FocusEvent thisEvent)
{
hours.setText("");
rate.setText("");
gross.setText("");
net.setText("");
}
}
}
Here is my html code:
<HTML>
<APPLET CODE = "Calculate.class" WIDTH = 450 HEIGHT = 200>
</APPLET>
</HTML>