/** A very simple example of a Java GUI application that responds ** to button events. **/ // AWT components and Event classes used: import java.awt.Button; import java.awt.Frame; import java.awt.event.ActionListener; // interface import java.awt.event.ActionEvent; // events that interface relates to public class SimpleGUI2 implements ActionListener { private Frame appFrame = null; private Button doSomethingButton = null; public static void main(String[] args) { SimpleGUI2 app = new SimpleGUI2(); app.run(); } /** Constructor: make a frame to hold the GUI components and the ** GUI components themselves. **/ public SimpleGUI2() { appFrame = new Frame("Simple Java GUI"); doSomethingButton = new Button("Do Something"); // This object that is being constructed agrees to listen for // events the button will generate. doSomethingButton.addActionListener(this); appFrame.add(doSomethingButton); } /** run the application **/ public void run() { appFrame.validate(); appFrame.setVisible(true); } public void actionPerformed(ActionEvent e) { System.out.println("You pressed the button"); } }