Hello I just started using Processing. I intend to have this code such that when the buttons are pressed, they disappear. However when I click, the buttons remain on screen. How do I fix this?
Pardon my unusual way of commenting
import controlP5.*;
import processing.serial.*;
//Serial port = new Serial(this, "COM4", 9600); //COMport and baud rate
ControlP5 cp5_A;
ControlP5 cp5_B;
PFont buttonfont;
PFont optionfont;
//\\ Main setup
void setup() {
//\\ Primary customisation
size(640, 300);
background(249, 250, 255);
textSize(24);
smooth();
fill(0);
text("Control Centre", 10, 30);
//\\ Fonts
buttonfont = createFont("Arial", 18, true);
optionfont = createFont("Arial", 12, true);
//\\ Initialise controller layers and relevant buttons
cp5_A = new ControlP5(this);
cp5_A.addButton("single")
.setPosition(170, 110)
.setSize(100, 60)
.setFont(buttonfont)
.setId(1);
cp5_A.addButton("swarm")
.setPosition(370, 110)
.setSize(100, 60)
.setFont(buttonfont)
.setId(2);
cp5_A.addButton("manual")
.setPosition(540, 0)
.setSize(100, 60)
.setFont(buttonfont)
.setId(3);
cp5_A.addButton("options")
.setPosition(0, 270)
.setSize(80, 30)
.setFont(optionfont)
.setId(4);
cp5_B = new ControlP5(this);
}
//\\ Functions
public void addHome(){
cp5_B.addButton("Home")
.setPosition(580, 270)
.setSize(60, 30)
.setFont(optionfont);
}
public void clearPage(){
//clears the page so as to make space for new controllers (except title)
/*cp5_A.remove("single");
cp5_A.remove("swarm");
cp5_A.remove("options");
cp5_A.remove("manual");*/
cp5_A.hide();
}
public void single(){
println("single option");
}
public void swarm(){
}
public void options(){
}
public void home(){
//
}
//\\ Actual loop
void draw(){
if(cp5_A.isMouseOver(cp5_A.getController("single")) & mousePressed){
addHome();
clearPage();
single();
}
else if (cp5_A.isMouseOver(cp5_A.getController("swarm")) & mousePressed){
clearPage();
addHome();
swarm();
}
else if (cp5_A.isMouseOver(cp5_A.getController("options")) & mousePressed){
clearPage();
addHome();
options();
}
else if (cp5_B.isMouseOver(cp5_B.getController("Home")) & mousePressed){
clearPage();
home();
println("aaaaa");
}
}