PrintWriter output; in controlP5
in
Contributed Library Questions
•
1 year ago
dear all,
i am using controlP5 to checkbox.
i have got 27 buttons in 3 rows and 9 columns.
i need to PrintWriter output; the button i pressed. but i can't find what do i need to write. i am using;
output.println("Checkbox selected:" + theEvent.group());
but it is not working.
and if possible instead of the number the example gives me
ControlP5 0.5.4 infos, comments, questions at
http://www.sojamo.de/libraries/controlP5
got an event from checkBox
100000000000000000000000000
got an event from checkBox
100000000100000000000000000
got an event from checkBox
100000000100000000100000000
...
i need
ControlP5 0.5.4 infos, comments, questions at
http://www.sojamo.de/libraries/controlP5
got an event from checkBox
button 1
got an event from checkBox
button 12
got an event from checkBox
button 9
...
import controlP5.*;
ControlP5 controlP5;
CheckBox checkbox;
PImage b;
PrintWriter output;
void setup() {
output = createWriter("positions.txt");
size(512, 350);
smooth();
noStroke();
controlP5 = new ControlP5(this);
checkbox = controlP5.addCheckBox("checkBox",103,63);
//make adjustments to the layout of a checkbox.
checkbox.setColorForeground(color(255));
checkbox.setColorActive(color(255,0,0));
checkbox.setColorLabel(color(0));
checkbox.setItemsPerRow(9);
checkbox.setSpacingColumn(27);
checkbox.setSpacingRow(124);
// add items to a checkbox.
checkbox.addItem("1",0);
checkbox.addItem("2",10);
checkbox.addItem("3",50);
checkbox.addItem("4",100);
checkbox.addItem("5",200);
checkbox.addItem("6",5);
checkbox.addItem("7",0);
checkbox.addItem("8",10);
checkbox.addItem("9",50);
checkbox.addItem("10",100);
checkbox.addItem("11",200);
checkbox.addItem("12",5);
checkbox.addItem("13",0);
checkbox.addItem("14",10);
checkbox.addItem("15",50);
checkbox.addItem("16",100);
checkbox.addItem("17",200);
checkbox.addItem("18",5);
checkbox.addItem("19",0);
checkbox.addItem("20",10);
checkbox.addItem("21",50);
checkbox.addItem("22",100);
checkbox.addItem("23",200);
checkbox.addItem("24",5);
checkbox.addItem("25",100);
checkbox.addItem("26",200);
checkbox.addItem("27",5);
}
void keyPressed() {
println(char(1)+" / "+keyCode);
if(key==' '){
checkbox.deactivateAll();
} else {
for(int i=0;i<6;i++) {
// check if key 0-5 have been pressed and toggle
// the checkbox item accordingly.
if(keyCode==(48 + i)) {
// the index of checkbox items start at 0
checkbox.toggle(i);
println("toggle "+checkbox.getItem(i).name());
// also see
// checkbox.activate(index);
// checkbox.deactivate(index);
}
}
}
}
void draw() {
background(0);
b = loadImage("manikin.jpg");
image(b, 0, 0, width, height);
}
void controlEvent(ControlEvent theEvent) {
if(theEvent.isGroup()) {
print("got an event from "+theEvent.group().name()+"\t");
// checkbox uses arrayValue to store the state of
// individual checkbox-items. usage:
for(int i=0;i<theEvent.group().arrayValue().length;i++) {
int n = (int)theEvent.group().arrayValue()[i];
print(n);
if(n==1) {
}
}
println();
output.println("Checkbox selected:" + theEvent.group());
}
}
void mousePressed() {
output.flush(); // Writes the remaining data to the file
output.close(); // Finishes the file
//exit(); // Stops the program
}
1