import
java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
public class Hangman extends JApplet implements ActionListener {
//
create the text field here so I can refer to it in any method
JTextField
wordField = new JTextField(24);
public void init() {
// it is up to you to write code here that creates the
//graphical user interface, the buttons, menu etc.
// create some buttons
JButton buttonA = new JButton ("A");
JButton buttonB = new JButton ("B");
// register an event listener on each button
buttonA.addActionListener(this)
buttonB.addActionListener(this)
// set an action command to identify each button
buttonA.setActionCommand("buttonA")
buttonB.setActionCommand("buttonB")
}
// method for handling Action Events
public void actionPerformed (ActionEvent e) {
if e.getActionCommand == "buttonA" {
wordField.setText("A");
}
if e.getActionCommand == "buttonB" {
wordField.setText("B");
}
}
}
|