/************************************************************** / Golf Handicap Applet / IKE / Started: 5/24/01 /**************************************************************/ import java.awt.*; import java.applet.*; import java.awt.event.*; import java.text.DecimalFormat; public class Handicap extends Applet implements ActionListener { public TextField input1, input2, input3, display; public Label labelTitle, label1input, label2input, label3input; public Button b1; Font f; public int score; public float handicap, course, slope; public void init() { setBackground(Color.green); f = new Font("", Font.ITALIC, 12); setFont(f); input1 = new TextField(6); input1.setBackground(Color.white); input2 = new TextField(6); input2.setBackground(Color.white); input3 = new TextField(6); input3.setBackground(Color.white); display = new TextField(6); display.setEditable(false); display.setBackground(Color.white); labelTitle = new Label("Golf Handicap Calculator"); label1input = new Label("Score "); label2input = new Label("Course Rating "); label3input = new Label("Slope Rating "); b1 = new Button("Compute Handicap"); b1.addActionListener(this); b1.setBackground(Color.lightGray); add(labelTitle); add(label1input); add(input1); add(label2input); add(input2); add(label3input); add(input3); add(b1); add(display); } public void actionPerformed(ActionEvent e) { DecimalFormat twoDigits = new DecimalFormat( "0.00"); score = Integer.parseInt(input1.getText()); course = Integer.parseInt(input2.getText()); slope = Integer.parseInt(input3.getText()); handicap = ((score - course) * 113 / slope); display.setText(""+twoDigits.format(handicap)); } }