Java Reference
In-Depth Information
L ISTING 7.8 Continued
* @author Mauro Marinilli
* @version 1.0
*/
public class AccountApplet extends ClientDeploylet {
JButton calcButton = new JButton();
JTextField hoursTextField = new JTextField(4);
JTextField hpdTextField = new JTextField(4);
JLabel resultLabel = new JLabel();
/**Construct the applet*/
public AccountApplet() {
}
/**Initialize the applet*/
public void initApplication() {
//...
}
/**Start the applet*/
public void startApplication() {
log(“account applet started”);
}
/**
* throws an exception
*/
void calculate(ActionEvent e) {
try {
// hopefully we'll get an exception here
int hours = Integer.valueOf(hoursTextField.getText()).intValue();
int hpd = Integer.valueOf(hpdTextField.getText()).intValue();
resultLabel.setText(hours / hpd + “ days”);
}
catch (Exception ex) {
log(ex);
}
}
}
Note that our AccountApplet doesn't implement the usual start , stop ,and init methods, but
similar methods with different names ( startApplication at line 30 of Listing 7.8,
stopApplication that we didn't implement in this applet, and initApplication at line 25).
Search WWH ::




Custom Search