This post is in response to the message you sent to me regarding handling option selection events when using the GUI builder tool. With regard to resizing windows etc. then I am sure others can add to this thread.
--------------------------------------------------------------------------------------------------------------------------------------------------
I used the GUI biuilder tool to create the simple demo application shown listed
There are two option groups:-
Group 1 has three option buttons to select the colour and
Group 2 has two option buttons to select light/dark.
In the builder tool I canged the variable name and event method name to make it easier to identify the event handlers. They are :-
Variable name Event Method name
optRed option_red_select
optGreen option_green_select
optBlue option_blue_select
optDark option_dark_select
optLight option_light_select
The five event methods are at the start of the gui tab and these are executed when the corresponding option is selected.
Main Sketch Tab:
- // Need G4P library
- import guicomponents.*;
- int backCol;
- int r,g,b;
- boolean dark = false;
- void setup(){
- size(480, 320);
- createGUI();
- customGUI();
- // Place your setup code here
- r = b = 0;
- g = 250;
- }
- void draw(){
- background(r,g,b);
- fill(200);
- noStroke();
- rect(0,0,240,100);
- }
- // Use this method to add additional statements
- // to customise the GUI controls
- void customGUI(){
- }
gui tab
- /* =========================================================
- * ==== WARNING ===
- * =========================================================
- * The code in this tab has been generated from the GUI form
- * designer and care should be taken when editing this file.
- * Only add/edit code inside the event handlers i.e. only
- * use lines between the matching comment tags. e.g.
- void myBtnEvents(GButton button) { //_CODE_:button1:12356:
- // It is safe to enter your event code here
- } //_CODE_:button1:12356:
-
- * Do not rename this tab!
- * =========================================================
- */
- void option_red_select(GOption opt_selected, GOption opt_deselected) { //_CODE_:optRed:589177:
- r = g = b = 0;
- r = 250;
- if (dark == true)
- r = 125;
- } //_CODE_:optRed:589177:
- void option_green_select(GOption opt_selected, GOption opt_deselected) { //_CODE_:optGreen:689373:
- r = g = b = 0;
- g = 250;
- if (dark == true)
- g = 125;
- } //_CODE_:optGreen:689373:
- void option_blue_select(GOption opt_selected, GOption opt_deselected) { //_CODE_:optBlue:669478:
- r = g = b = 0;
- b = 250;
- if (dark == true)
- b = 125;
- } //_CODE_:optBlue:669478:
- void option_light_select(GOption opt_selected, GOption opt_deselected) { //_CODE_:optLight:808969:
- if (r == 125)
- r = 250;
- if (g == 125)
- g = 250;
- if (b == 125)
- b = 250;
- dark = false;
- } //_CODE_:optLight:808969:
- void option_dark_select(GOption opt_selected, GOption opt_deselected) { //_CODE_:optDark:825304:
- if (r == 250)
- r = 125;
- if (g == 250)
- g = 125;
- if (b == 250)
- b = 125;
- dark = true;
- } //_CODE_:optDark:825304:
- // Create all the GUI controls.
- // autogenerated do not edit
- void createGUI(){
- G4P.setColorScheme(this, GCScheme.BLUE_SCHEME);
- G4P.messagesEnabled(false);
- optGroup1 = new GOptionGroup();
- optRed = new GOption(this, "Red", 32, 8, 90);
- optGroup1.addOption(optRed);
- optRed.addEventHandler(this, "option_red_select");
- optGreen = new GOption(this, "Green", 32, 32, 90);
- optGroup1.addOption(optGreen);
- optGreen.setSelected(true);
- optGreen.addEventHandler(this, "option_green_select");
- optBlue = new GOption(this, "Blue", 32, 56, 90);
- optGroup1.addOption(optBlue);
- optBlue.addEventHandler(this, "option_blue_select");
- optGroup2 = new GOptionGroup();
- optLight = new GOption(this, "Light", 136, 24, 90);
- optGroup2.addOption(optLight);
- optLight.setSelected(true);
- optLight.addEventHandler(this, "option_light_select");
- optDark = new GOption(this, "Dark", 136, 48, 90);
- optGroup2.addOption(optDark);
- optDark.addEventHandler(this, "option_dark_select");
- }
- // Variable declarations
- // autogenerated do not edit
- GOptionGroup optGroup1;
- GOption optRed;
- GOption optGreen;
- GOption optBlue;
- GOptionGroup optGroup2;
- GOption optLight;
- GOption optDark;
Hope this example helps