Hello Friends, I am working on checkBox array. I want to display the result for example, if i check the first checkbox from array one and the array 3 it will show me result that [11] and [31] are selected. i wanna create a true false table,
here is my code.
import g4p_controls.*;
public void setup() {
size(480, 320, JAVA2D);
createGUI();
customGUI();
// Place your setup code here
}
public void draw() {
background(230);
}
// Use this method to add additional statements
// to customise the GUI controls
public void customGUI() {
}
public void textfield1_change1(GTextField source, GEvent event) { //CODE:txtno:852228:
} //CODE:txtno:852228:
public void button2_click2(GButton source, GEvent event) { //_CODE_:button1:882560:
println("button1 - GButton >> GEvent." + event + " @ " + millis());
} //_CODE_:button1:882560:
public void button1_click1(GButton source, GEvent event) { //CODE:btnSubmit:452090:
String actant = txtno.getText();
if (actant.isEmpty()) {
println("increase the number of acctant");
} else {
int i = Integer.parseInt(txtno.getText());
if (i > 0) {
cbxArray = new GCheckbox[i][3];
for (int x=0; x < i; x++) { //Actant number to display
lblTitle = new GLabel(this, 5, 40 + 20 * x, 85, 20);
lblTitle.setText("Actant No: "+ (x+1) + ".");
lblTitle.setOpaque(false);
for (int j=0; j<3; j++) {
//For Creating checkbox
cbxArray[x][j] = new GCheckbox(this, 105+100*j, 40 + 20 * x, 85, 20);
cbxArray[x][j].setTextAlign(GAlign.LEFT, GAlign.MIDDLE);
if (j==1) {
cbxArray[x][j].setText("Noise");
} else if (j==2) {
cbxArray[x][j].setText("Smell");
} else {
cbxArray[x][j].setText("Heat");
}
cbxArray[x][j].setOpaque(false);
cbxArray[x][j].addEventHandler(this, "cbx_array_handler");
cbxArray[x][j].tagNo = (x+1)*1000 + j + 1;
}
}
}
}
} //CODE:btnSubmit:452090:
// Create all the GUI controls. // autogenerated do not edit
public void createGUI() {
G4P.messagesEnabled(false);
G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
G4P.setCursor(ARROW);
surface.setTitle("Sketch Window");
lblActant = new GLabel(this, 5, 5, 95, 22);
lblActant.setText("Actant Number");
lblActant.setTextBold();
lblActant.setOpaque(false);
txtno = new GTextField(this, 104, 4, 43, 30, G4P.SCROLLBARS_NONE);
txtno.setOpaque(true);
txtno.addEventHandler(this, "textfield1_change1");
btnSubmit = new GButton(this, 158, 8, 80, 30);
btnSubmit.setText("Submit");
btnSubmit.addEventHandler(this, "button1_click1");;
G4P.messagesEnabled(false);
G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
G4P.setCursor(ARROW);
surface.setTitle("Sketch Window");
button2 = new GButton(this, 332, 278, 80, 30);
button2.setText("Result");
button2.addEventHandler(this, "button2_click2");
}
// Variable declarations // autogenerated do not edit
GLabel lblActant;
GTextField txtno;
GButton btnSubmit;
GLabel lblTitle;
// Create Checkbox array
GCheckbox[][] cbxArray;
public void cbx_array_handler(GCheckbox checkbox, GEvent event) {
int actant_nbr = checkbox.tagNo / 1000;
int cbx_nbr = checkbox.tagNo % 1000;
print("Checkbox click for actant nbr: " + actant_nbr + " for checkbox: ");
switch(cbx_nbr) {
case 1:
print("Heat");
break;
case 2:
print("Noise");
break;
case 3:
print("Smell");
break;
default:
print("Unknown");
}
println(" value: " + checkbox.isSelected());
}
GButton button2;
Thank you in advance