Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Show/Hide CP5 Button

$
0
0

Hi! I'm new to coding so sorry if this question is dumb but I can't figure out how to make a CP5 button hide once it's been clicked. I want the two buttons A and B to be the first to show then once they are clicked I want the buttons 1945, 1960, and 2015 to show and A and B to hide. Please help!

import controlP5.*;

ControlP5 cp5;

String myResponse1;
int myResponse2;
PImage show1947Israel, show1960Israel, show2015Israel, question;
boolean display = false;

void setup() {
  size(600, 600);
  background(255);

  cp5 = new ControlP5(this);

  cp5.addButton("A")
     .setPosition(210,300)
     .updateSize()
     ;

  cp5.addButton("B")
  .setPosition(310,300)
     .updateSize()
     ;

  cp5.addButton("1945")
     .setPosition(150,400)
     .updateSize()
     ;

cp5.addButton("1945").setSwitch(true);

  cp5.addButton("1960")
     .setPosition(250,400)
     .updateSize()
     ;

cp5.addButton("1960").setSwitch(true);

  cp5.addButton("2015")
     .setPosition(350,400)
     .updateSize()
     ;

cp5.addButton("2015").setSwitch(true);

question = loadImage("when.png");
show1947Israel = loadImage("1947map.png");
show1960Israel = loadImage("1960map.png");
show2015Israel = loadImage("2015map.png");

}

void draw(){
  hideButton();

}

void hideButton() {
 if (display == false) {
    cp5.addButton("1945").hide();
    cp5.addButton("1960").hide();
    cp5.addButton("2015").hide();
  }
  else {
   cp5.addButton("1945").show();
   cp5.addButton("1960").show();
   cp5.addButton("2015").show();
  }
}
  public void controlEvent(ControlEvent theEvent) {
  println(theEvent.getController().getName());
  }

// function A will receive changes from
// controller with name A
  public void A(int theValue) {
  println("a button event from A: "+theValue);
 showQuestion2();


  }
// function B will receive changes from
// controller with name B
  public void B(int theValue) {
  println("a button event from B: "+theValue);
showQuestion2();
  }

  void showQuestion2() {
   image(question, 0, 0, width, height);
   display = true;
  }

Viewing all articles
Browse latest Browse all 2896

Trending Articles