import com.sun.kjava.*; public class HelloButton extends Spotlet { // handle on the singleton Graphics object static Graphics g = Graphics.getGraphics(); // the GUI buttons Button testButton; Button exitButton; String outputString = "Push the Button Max"; /** * The main method simply creates a Scribble spotlet and * registers its event handlers. */ public static void main(String[] args) { (new HelloButton()).register(NO_EVENT_OPTIONS); } /** * Default constructor creates the GUI components and draws them. */ public HelloButton() { // create the button testButton = new Button("Push Me",60,100); exitButton = new Button("Exit",139,145); paint(); } /** * Draw the screen */ private void paint() { g.clearScreen(); g.drawString(" HelloButton Demo ", 34, 0, Graphics.INVERT); g.drawString(outputString, 50, 80); // Draw GUI controls and buttons exitButton.paint(); testButton.paint(); } /** * Handle a pen up event. */ public void penUp(int x, int y) { if (testButton.pressed(x,y)) { g.drawRectangle(50, 80, 90, 10, Graphics.ERASE, 0); outputString = "Button Up...."; g.drawString(outputString, 50, 80); } } /** * Handle a pen down event. */ public void penDown(int x, int y) { if (testButton.pressed(x,y)) { g.drawRectangle(50, 80, 90, 10, Graphics.ERASE, 0); outputString = "Button Down...."; g.drawString(outputString, 50, 80); } else if (exitButton.pressed(x,y)) { // The following is used with the KVM_EA1 version System.exit(0); // The following is used with the KVM_J1 version // Runtime.exit(); } } }