college/ss2010/gdi2/java/libs/acm/demo/StoplightConsole.java
2013-12-19 19:05:28 +01:00

42 lines
1.0 KiB
Java

/*
* File: StoplightConsole.java
* ---------------------------
* This program illustrates the construction of a simple GUI.
*/
import acm.program.*;
import java.awt.event.*;
import javax.swing.*;
/**
* This class displays three buttons at the south edge of the window.
* The name of the button is echoed on the console each time a button
* is pressed.
*/
public class StoplightConsole extends ConsoleProgram {
/** Initialize the GUI */
public void init() {
add(new JButton("Green"), SOUTH);
add(new JButton("Yellow"), SOUTH);
add(new JButton("Red"), SOUTH);
addActionListeners();
}
/** Listen for a button action */
public void actionPerformed(ActionEvent e) {
println(e.getActionCommand());
}
/** Set the program dimensions */
public static final int APPLICATION_WIDTH = 350;
public static final int APPLICATION_HEIGHT = 250;
/* Standard Java entry point */
/* This method can be eliminated in most Java environments */
public static void main(String[] args) {
new StoplightConsole().start(args);
}
}