Lab 14 class file
Terminate class
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Lab14 extends Frame implements ActionListener {
TextField rate = new TextField(10), hrs = new TextField(10), output = new TextField(15);
double pay;
boolean started = false;
public Lab14(){
super("Lab 14");
setSize(300,200);
Panel p1 = new Panel();
p1.add(new Label("Enter hourly rate: "));
p1.add(rate);
p1.add(new Label("Enter hours worked: "));
p1.add(hrs);
p1.add(output);
add(p1);
rate.addActionListener(this);
hrs.addActionListener(this);
setVisible(true);
addWindowListener(new Terminate());
} // End constructor
public void paint(Graphics g){
if (started) {
try{
pay = ((new Double(rate.getText()).doubleValue()) * (new Double(hrs.getText()).doubleValue()));
}
catch (Exception e){};
output.setText("Pay is $" + pay);
} // End IF
else started = true;
} // Ends Paint
public void actionPerformed(ActionEvent e){
if (e.getSource() == rate){
hrs.requestFocus();
repaint();
}
else {rate.requestFocus(); repaint();}
} // End ActionPerformed
public static void main(String[] args){
new Lab14();
} // End of main
} // Ends Class
class Terminate extends WindowAdapter {
public void windowClosing(WindowEvent e){
System.exit(0);
}
}