package COM.jconsort.ui; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; /** * Tests and shows how to use MessageBox. * * @author Jack Harich */ public class MessageBoxTest implements ActionListener { //---------- Private Fields ------------------------------ // (none) //---------- Initialization ------------------------------ public MessageBoxTest() { // Apologies, this story is from memory and may be wrong String message = "There's an old story called the Lady and the Tiger."; message += "\nYou are placed in an arena with two doors."; message += "\nBehind one is the farest lady in the land, but"; message += "\n behind the other is a starving tiger."; message += "\nA friend has told you which door has the lady,"; message += "\n but your rival may have switched doors."; message += "\n\nYou must choose a door."; MessageBox box = new MessageBox(this); box.setTitle("The $64,000 Question"); box.useImageCanvas("LightBulb.gif"); box.addChoice("Lady"); box.addChoice("Tiger"); box.addChoice("Help"); box.setCloseWindowCommand("Close"); box.ask(message); } public static void main(String args[]) { new MessageBoxTest(); } //---------- PactionPerformed Implementation ------------- public void actionPerformed(ActionEvent evt) { String command = evt.getActionCommand(); if (command.equals("Lady")) { print("Whoops, there really is a tiger behind the Lady door."); } else if(command.equals("Tiger")) { print("Ahhh, there really is a lady behind the Tiger door."); } else if(command.equals("Help")) { print("Help is not yet implemented. :>)"); } else if(command.equals("Close")) { print("Hmmmm, why take a chance? You choose Close"); } print(" Test complete"); System.exit(0); } //---------- Private Methods ----------------------------- //--- Std private static void print(String text) { System.out.println(text); } } // End class