home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Java / Java.zip / jmsgbx11.zip / test.java < prev   
Text File  |  1996-11-25  |  3KB  |  101 lines

  1. /*
  2. File: test.java
  3. Description: Test MsgBox
  4. Date: 25.Nov 1996
  5. Author: Henrik Falk
  6.         2:236/89@fidonet.org
  7.         81:445/16@os2net.ftn
  8.         hfalk@ibm.net
  9.  
  10.         Released into Public Domain.
  11. */
  12.  
  13. import java.awt.*;
  14.  
  15. /********************************************************************
  16. * Class: test
  17. ********************************************************************/
  18. public class test extends Frame
  19. {
  20.   protected Button testButton;
  21.  
  22.   /******************************************************************
  23.   * Function: main()
  24.   ******************************************************************/
  25.   public static void main(String args[])
  26.     {
  27.  
  28.       test mainApp=new test("Test Application");
  29.  
  30.            mainApp.resize(400,200);
  31.            mainApp.show();
  32.  
  33.     } // end function main()
  34.  
  35.   /******************************************************************
  36.   * Constructor: test()
  37.   ******************************************************************/
  38.   public test(String mainTitle)
  39.     {
  40.  
  41.       super(mainTitle);
  42.  
  43.       testButton=new Button("Test me!");
  44.       Panel c=new Panel();
  45.             c.setLayout(new FlowLayout());
  46.             c.add(testButton);
  47.       this.add("Center",c);
  48.  
  49.     } // end constructor test()
  50.  
  51.   /******************************************************************
  52.   * Method: handleEvent()
  53.   ******************************************************************/
  54.   public boolean handleEvent(Event evt)
  55.     {
  56.  
  57.       switch(evt.id)
  58.        {
  59.         case Event.WINDOW_DESTROY: 
  60.                    System.exit(0);
  61.                    return false;
  62.         } // endswitch
  63.  
  64.     if(evt.target instanceof Button)
  65.       {
  66.       String choice=(String)evt.arg;
  67.  
  68.       if(choice.equals("Test me!"))
  69.         {
  70.         int result;
  71.  
  72.         MsgBox msg=new MsgBox();
  73.         result=msg.show(MsgBox.MB_YESNO,"Test Application","Press 'Yes' or 'No'");
  74.  
  75.         String response;
  76.         switch(result)
  77.           {
  78.             case MsgBox.MBID_YES:
  79.                         response=new String("Yes");
  80.                         break;
  81.             case MsgBox.MBID_NO:
  82.                         response=new String("No");
  83.                         break;
  84.             default:
  85.                         response=new String("Ouups!");
  86.                         break;
  87.           } // endswitch
  88.  
  89.         MsgBox msg2=new MsgBox();
  90.                msg2.show(MsgBox.MB_OK,"Test Application",
  91.                     "You pressed: "+response);
  92.  
  93.         } // endif
  94.       } // endif
  95.  
  96.       return false;
  97.  
  98.     } // end method handleEvent()
  99.  
  100. } // end class test
  101.