G4P Label Array Test
I’ve been trying to make a label array with the G4P Library in Processing 3. I’m having a problem with the “setText()” to an Array. Here’s the sketch. I’ve documented to problem area. Maybe someone can help. Run the sketch. Let me know what you think. Thanks everyone.
import g4p_controls.*;
GWindow window;
GLabel lbl1, lbl2;
GLabel[] lblArray= new GLabel[5];
String [] testArray= new String[5];
public void setup() {
size(100,300);
for(int i=0; i < 5; i++){
testArray[i]=("["+i+"] "+ "test");
println(testArray[i]);
}
window = GWindow.getWindow(this, "G4P Label Array Test", 210, 210, 500, 200, JAVA2D);
window.addDrawHandler(this, "windowDraw");
lbl1 = new GLabel(window, 10, 20, 200, 18);
lbl1.setTextAlign(GAlign.LEFT, null);
lbl1.setOpaque(true);
lbl2 = new GLabel(window, 10, 48, 200, 18);
lbl2.setTextAlign(GAlign.LEFT, null);
lbl2.setOpaque(true);
for(int i=0; i < 5; i++){
lblArray[i] = new GLabel(window, 220, 20, 200, 20*i+1);
lblArray[i].setTextAlign(GAlign.LEFT, null);
lblArray[i].setOpaque(true);
}
for(int i=0; i < 5; i++){
lblArray[i].setText("["+i+"] "+ testArray[i]); /*THIS LINE ONLY SETS THE LAST ELEMENT OF THE ARRAY AND NOT IN THE CORRECT SPOT*/
println(lblArray[i]); //Look at he console output
}
}
public void draw() {
lbl1.setText("["+ 1 +"] "+ "Test" );
lbl2.setText("["+ 2 +"] "+ "Test");
}
public void windowDraw(PApplet app, GWinData data){
app.background(0);
}