I would like to be able to use radio buttons to represent numbers and
then have the result of his choices appear in a text field
Need more information than this to help you. How would you see the program being used by your son, for instance describe how your son might use the program..
So far you have created 2 option groups and each group has 2 options. You say you want the result to appear in the textfield but the result of what?
The code below will allow the user to select from one of two numbers for the first option group and the same for the second option group and will display "You have selected ?? and ??" replacing the ?? with the numbers selected.
- // Need G4P library
- import guicomponents.*;
- float n1, n2; // two numbers for the user selection
- void setup(){
- size(480, 320);
- createGUI();
- customGUI();
- // Place your setup code here
- n1 = 0;
- n2 = 0;
- }
- void draw(){
- background(200,220,200);
- }
- // Use this method to add additional statements
- // to customise the GUI controls
- void customGUI(){
- }
- void updateResultText(){
- result.setText("You have selected " + n1 + " and " + n2);
- }
- /* =========================================================
- * ==== 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 option1_Click1(GOption opt_selected, GOption opt_deselected) { //_CODE_:one:233963:
- n1 = 1;
- updateResultText();
- } //_CODE_:one:233963:
- void option2_Click1(GOption opt_selected, GOption opt_deselected) { //_CODE_:two:593628:
- n1 = 2;
- updateResultText();
- } //_CODE_:two:593628:
- void option3_Click1(GOption opt_selected, GOption opt_deselected) { //_CODE_:three:842041:
- n2 = 3;
- updateResultText();
- } //_CODE_:three:842041:
- void option4_Click1(GOption opt_selected, GOption opt_deselected) { //_CODE_:four:648498:
- n2 = 4;
- updateResultText();
- } //_CODE_:four:648498:
- void textfield1_Enter1(GTextField textfield) { //_CODE_:result:239776:
- println("textfield1 - GTextField event occured " + System.currentTimeMillis()000000 );
- } //_CODE_:result:239776:
- // Create all the GUI controls.
- // autogenerated do not edit
- void createGUI(){
- G4P.setColorScheme(this, GCScheme.BLUE_SCHEME);
- G4P.messagesEnabled(false);
- optGroup1 = new GOptionGroup();
- one = new GOption(this, "1", 13, 74, 90);
- optGroup1.addOption(one);
- one.setSelected(true);
- one.addEventHandler(this, "option1_Click1");
- two = new GOption(this, "2", 13, 112, 90);
- optGroup1.addOption(two);
- two.addEventHandler(this, "option2_Click1");
- optGroup2 = new GOptionGroup();
- three = new GOption(this, "3", 141, 73, 90);
- optGroup2.addOption(three);
- three.setSelected(true);
- three.addEventHandler(this, "option3_Click1");
- four = new GOption(this, "4", 140, 114, 90);
- optGroup2.addOption(four);
- four.addEventHandler(this, "option4_Click1");
- result = new GTextField(this, "result", 269, 90, 80, 20, false);
- result.addEventHandler(this, "textfield1_Enter1");
- }
- // Variable declarations
- // autogenerated do not edit
- GOptionGroup optGroup1;
- GOption one;
- GOption two;
- GOptionGroup optGroup2;
- GOption three;
- GOption four;
- GTextField result;
Try playing with the eaxamples that come with the library to see how the controls work.