import GUI ; import Graphics ; // ============================================= // GUI Component Setup - Start // ============================================= // Create a window at (x, y) = (300, 20) with width 360 and height 480 int windowID = newWindow( 300, 20, 360, 480, "Hello GUI" ) ; // Create a button at (10, 10) with width 100 and height 50 int buttonID = newButton ( 10, 10, 100, 50, "PUSH" ) ; mountComponent( buttonID, windowID ) ; // Create a text field at (10, 70) with size 100 ~ 30 int textFieldD = newTextField( 10, 70, 100, 30, "INPUT" ) ; mountComponent( textFieldD, windowID ) ; // Create a text area at (120, 10) with size 200 ~ 200 int textAreaID = newTextArea( 120, 10, 200, 200, "INPUT" ) ; mountComponent( textAreaID, windowID ) ; // Create a select field at (10, 110) with size 100 ~ 20 string text[ 3 ] ; text[ 0 ] = "TYPE-A"; text[ 1 ] = "TYPE-B"; text[ 2 ] = "TYPE-C"; int selectFieldID = newSelectField( 10, 110, 100, 20, text ) ; mountComponent( selectFieldID, windowID ) ; // Create a checkbox at (10, 140) with size 100 ~ 20 int checkBoxID = newCheckBox( 10, 140, 100, 20, "TURBO", true ) ; mountComponent( checkBoxID, windowID ) ; // Create a text label at (10, 170) with size 100 ~ 20 int textLabelID = newTextLabel( 10, 170, 100, 20, "Hello GUI ! " ) ; mountComponent( textLabelID, windowID ) ; // Load an image file named "Test.png" int graphicsID = newGraphics( "Test.png" ) ; // Create an image label at (10, 220) with size 310 ~ 200 int imageLabelID = newImageLabel( 10, 220, 310, 200, graphicsID ) ; mountComponent( imageLabelID, windowID ) ; // ============================================= // GUI Component Setup - End // ============================================= // ============================================= // Event Handlers - Start // ============================================= // Called when the window is closed void onWindowClose( int id ){ alert( "The program will now exit." ) ; exit( ); } // Called when the button is clicked void onButtonClick( int id, string text ){ alert( "Button \"" + text + "\" was clicked." ) ; } // Called when a select field option is selected void onSelectFieldClick( int id, string text ){ alert( "\"" + text + "\" was selected." ) ; } // Called when the checkbox is toggled void onCheckBoxClick( int id, bool state ){ alert( "Checkbox state changed to: " + state ) ; } // Called when the mouse is dragged void onMouseDrag( int id, int x, int y, int button ){ // Check which component was dragged if( id == imageLabelID ){ // Check which mouse button was used if( button == MOUSE_RIGHT ){ println( "Right drag - X=" + x + " Y=" + y ) ; }else if( button == MOUSE_LEFT ){ println( "Left drag - X=" + x + " Y=" + y ) ; } } } // Called when the mouse is clicked void onMouseClick( int id, int x, int y, int button, int count ){ // Check which component was clicked if( id == imageLabelID ){ // Check which mouse button was used if( button == MOUSE_RIGHT ){ println( "Right click - X=" + x + " Y=" + y ) ; }else if( button == MOUSE_LEFT ){ println( "Left click - X=" + x + " Y=" + y ) ; } // Check whether it was a double-click if( count == MOUSE_DOUBLE ){ alert( "Double-click detected." ); } } } // Called on key press (string-based) void onKeyDown( int id, string key ){ println( "Key pressed: " + key ) ; } // Called on key press (keycode-based) void onKeyDown( int id, int keyCode ){ if( keyCode == KEY_SPACE ){ alert( "Space key was pressed." ) ; } } // ============================================= // Event Handlers - End // =============================================