import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class actionTest implements ActionListener {
JFrame frame;
JPanel panel;
JTextField textField;
JButton button[];
Container contentPane;
void launchFrame() {
frame = new JFrame("Action Test");
panel = new JPanel();
textField = new JTextField("0", 20);
button = new JButton[2];
contentPane = frame.getContentPane();
button[1] = new JButton("1");
button[2] = new JButton("2");
panel.add(textField);
panel.add(button[1]);
panel.add(button[2]);
contentPane.add(panel);
frame.pack();
frame.setVisible(true);
}
public void actionPerformed(ActionEvent event) {
if(event.getSource() == button[1]) {
textField.setText("Button 1 pressed.");
}
else if(event.getSource() == button[2]) {
textField.setText("Button 2 pressed.");
}
else
textField.setText("Error.");
}
public static void main(String[]args) {
actionTest at = new actionTest();
at.launchFrame();
}
}

