Hello friends, I am trying to control the code to display with checkbox, I have two function
void render() and display ()
which i call in event control and with if else statement I want to display this. but it is not show. and when i put it event handler function in run() function its give error that variables are not declared. could you please point our my mistake.
I created checkbox with G4P GUI Builder.
my code is here.
` // 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"); chkBox = new GCheckbox(this, 4, 8, 123, 31); chkBox.setTextAlign(GAlign.LEFT, GAlign.MIDDLE); chkBox.setText("Display Nuclus ID"); chkBox.setTextBold(); chkBox.setOpaque(false); chkBox.addEventHandler(this, "chkNucleus"); }
// Variable declarations // autogenerated do not edit GCheckbox chkBox; //nucleus is the centre of the niche
class Nucleus {
int id; PVector pos; PVector nucleus = new PVector(); boolean frozen; /............................................................................................./ Nucleus(int identity, boolean hunger, PVector loc) { id = identity;
pos = loc.get();
} /............................................................................................./
void run() {
updatePos();
//render();
// display();
//chkNucleus(GCheckbox source, GEvent event);
}
void updatePos() { // println(id, "current pos", pos); nucleus = new PVector(); for (int i=0; i<space.length; i++) { if (space[i].ref == id) { for (int j=0; j<space[i].nodes.length; j++) { nucleus.add(space[i].nodes[j].pos);
}
}
}
nucleus.div(numNodes);
// println("current nucleus", nucleus); // float d = pos.dist(nucleus); // if (d == 0) { // frozen = true; // println("FROZEN .........!!!!!!!!!!!!!!!"); // } pos = nucleus; // println(id, "new pos", pos); }
public void chkNucleus(GCheckbox source, GEvent event) { //CODE:chkBox:929344: //println("chkBox - GCheckbox >> GEvent." + event + " @ " + millis()); //println(event);
if(chkBox.isSelected()){ println("ok"); display(); } else{ println("no"); render();
} }
void render() { stroke(200, 70); // stroke(250, 50); noFill(); ellipse(pos.x, pos.y, 8, 8); stroke(10); point(pos.x, pos.y); }
void display(){ // to display number. stroke(200, 70); // stroke(250, 50); noFill(); ellipse(pos.x, pos.y, 8, 8); stroke(10); point(pos.x, pos.y); fill(200, 155, 0); textAlign(CENTER, CENTER);
text(id, pos.x, pos.y);
}
}
`
Many thanks