I’m converting code from p5 to processing. I was storing functions in an array. These functions create the buttons which I’m using in my application and allowed me to loop through the array to draw and manipulate the buttons as opposed to having to call each one individually.
Now calling them individually outside of the array works in processing, however I get a null pointer exception when I try to loop through the functions Ive stored in the array. Cant seem to find any documentation about this, so I’m just wandering if it is in fact possible.
Button [] buttons = {game,paths,switches,pathreset,pathfind,pathfind2,pathfind3,pathfind4,cluster,set_target,set_pathfinder,extract_circuit,back,reset};
for (int i=0;i<buttons.length;i++){
Button a = buttons[i];
a.draw();
a.logic();
}
class Button{
HashMap<String,Integer> hm = new HashMap<String,Integer>();
float x,y,w,h,value,ts;
color col,col2;
String label;
int toggle,id,stroke;
boolean on = false;
Button(float X,float Y,float w_,float h_, String Label){
x = X;
y = Y;
w = w_;
h = h_;
col = color(120);
label = Label;
toggle = 0;
ts = 12;
}
void draw (){
fill(col);
noStroke();
rect(x,y,w,h);
fill(0);
textSize(ts);
text(label,x+10,y+h-10);
}
void logic(){
if(toggle==1){
this.col = color(255,255,255,200);
this.stroke = 0;
this.col2 = color(0,0,0,175);
}
else{
this.stroke = 0;
this.col2 = color(255,255,255,175);
this.col = color(255,255,255,80);
}
if(toggle==2){
toggle=0;
}
};