Controlp5 (Numberbox, RadioButton, CheckBox) what to write after case statements

I am completely newbie (completely). I asked the question here, I received no answer. Here I did not upload the whole project to the link, I think it is clear what kind of help I am asking.
Good afternoon, I’m using the switch construct, but I don’t know how to write correctly for other values after case statements.
Only works at (minutesss = cp5.addButton) - 10, (Vin = cp5.addTextlabel) - 60.

The main error is below (function “setText (String)” is undefined. See screenshot.

How do I fix this for variables and write it correctly?

ImageButton;

Numberbox inputPULI;

Numberbox inputNapryzenieKV;

RadioButton CheckBoxuvum;

CheckBox P4;

See the GUI file!

A task:

ImageButton (button) - 20, the goal is to get a change of the picture in the window.

P4 = cp5.addCheckBox - 30 CHECK, the goal is to enable and disable changing the state of the checkbox in the window.

inputPULI = cp5.addNumberbox - 40 Bullet, the goal is to get an integer change in the window.

CheckBoxuvum = cp5.addRadioButton - 50 +/-, the goal is to enable and disable (+/-) the state of the checkbox in the window.

inputNapryzenieKV = cp5.addNumberbox - 70 Voltage, the goal is to get the change of the floating point number in the window.

In the Displaydata code, I marked this with a question.

In the future, I plan to send commands from the terminal via the com port to receive a change in the data state in the window for these values.

Screenshot of errors:

GUI:

int min1 = 0;
int PUL;
float NapryzenieKV;
boolean strata=false;

Button minutess;
ImageButton button;
Numberbox inputPULI;
Numberbox inputNapryzenieKV;
RadioButton CheckBoxuvum;
CheckBox P4;
Textlabel Vin;
Button connection;
Button Send;

public void setupUI()
{
cp5 = new ControlP5(this);
PFont fontn = createFont(“Times New Roman”, 18);
PFont p = createFont(“Times New Roman”, 18);
ControlFont font=new
ControlFont(p);
cp5.setFont(font);

connection = cp5.addButton(“toplug”)
.setCaptionLabel(“ПУСК”)
.setPosition(387, 30)
.setSize(150, 30);

serialPortsList = cp5.addDropdownList(“Порт”)
.setPosition(130, 30)
.setSize(150, 200)
.setItemHeight(30)
.setBarHeight(30);

minutess = cp5.addButton(“minutesss”)
.setCaptionLabel(“ВЫКЛ”)
.setPosition(145, 100)
.setSize(90, 25);

Send = cp5.addButton(“toapply”)
.setCaptionLabel(“Apply”)
.setPosition(510, 370)
.setSize(150, 30);

Vin = cp5.addTextlabel(“naprazhenie kondencatora”)
.setText(“Voltage K.V”)
.setFont(p)
.setColor(color(#00ffff))
.setPosition(45, 320);

CheckBoxuvum = cp5.addRadioButton(“UV/UM”)
.setPosition(155, 360)
.setSize(15, 15)
.setColorActive(color(255))
.setItemsPerRow(2)
.setSpacingColumn(85)
.addItem(“+”, 1)
.addItem(“-”, 2);

P4 = cp5.addCheckBox(“std2”)
.setPosition(150, 190)
.setSize(15, 15)
.setItemsPerRow(1)
.setSpacingColumn(30)
.setSpacingRow(20)
.addItem(“Check”, 2);

inputPULI = cp5.addNumberbox(“PUL”)
.setPosition(150, 220)
.setSize(80, 30)
.setColorValue(0xffffff00)
.setFont(p)
.setScrollSensitivity(1.1)
.setDirection(Controller.HORIZONTAL)
.setRange(1, 199)
.setValue(3);
Label labelinputPULI = inputPULI.getCaptionLabel();
labelinputPULI.setFont(font);
labelinputPULI.setColor(color(#00ffff));
labelinputPULI.toUpperCase(false);
labelinputPULI.setText(“Bullet”);
labelinputPULI.align(ControlP5.LEFT_OUTSIDE, CENTER);
labelinputPULI.getStyle().setPaddingLeft(-55);

inputNapryzenieKV = cp5.addNumberbox(“NapryzenieKV”)
.setPosition(150, 270)
.setSize(80, 30)
.setColorValue(0xffffff00)
.setFont(p)
.setScrollSensitivity(1.1)
.setMin(25)
.setMax(99)
.setMultiplier(0.01)
.setDirection(Controller.HORIZONTAL)
.setValue(25);
Label labelinputNapryzenieKV = inputNapryzenieKV.getCaptionLabel();
labelinputNapryzenieKV.setFont(font);
labelinputNapryzenieKV.setColor(color(#00ffff));
labelinputNapryzenieKV.toUpperCase(false);
labelinputNapryzenieKV.setText(“Voltage”);
labelinputNapryzenieKV.align(ControlP5.LEFT_OUTSIDE, CENTER);
labelinputNapryzenieKV.getStyle().setPaddingLeft(-45);

textFont(fontn);
{
// button dimensions
int w = 99;
int h = 25;
// test with generated images
button = new ImageButton(140, 140, w, h,
new PImage{
getImage(w, h, color(192, 0, 32 * 2)), // off
getImage(w, h, color(0, 0, 32 * 3)), // 10
getImage(w, h, color(0, 0, 32 * 4)), // 20
getImage(w, h, color(0, 0, 32 * 5)), // 30
getImage(w, h, color(0, 0, 32 * 6)), // 40
getImage(w, h, color(0, 0, 32 * 7)), // 50
getImage(w, h, color(0, 0, 32 * 8)), // 60
});
}
}
void mousePressed() {
button.mousePressed(mouseX, mouseY);
println(button.min);
}
// test images to represent loaded state images
PImage getImage(int w, int h, int c) {
PImage img = createImage(w, h, RGB);
java.util.Arrays.fill(img.pixels, c);
img.updatePixels();
return img;
}

// make a custom image button class
class ImageButton {
// minutes is the data it stores
int min = 0;
// images for each state
PImage stateImages;
// which image to display
int stateIndex;
// position
int x, y;
// dimensions: width , height
int w, h;
// text to display
String label = “ВЫКЛ”;

ImageButton(int x, int y, int w, int h, PImage stateImages) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.stateImages = stateImages;
}
void mousePressed(int mx, int my) {
// check the cursor is within the button bounds
boolean isOver = ((mx >= x && mx <= x + w) && // check horizontal
(my >= y && my <= y + h) ); // check vertical

if (isOver) {

  min += 10;
  stateIndex++;

  if (min>60) {
    min = 0; 
    stateIndex = 0;
    label = "ВЫКЛ";
  } else {
    label = (str(min) + "Мин");
  }
}

}
void draw() {
// if the images and index are valid
if (stateImages != null && stateIndex < stateImages.length) {
image(stateImages[stateIndex], x, y, w, h);
} else {
println(“error displaying button state image”);
println("stateImages: ");
printArray(stateImages);
println("stateIndex: " + stateIndex);
}
// display text
text(label, x + 17, y + h - 8);
}
}
public void minutesss() {

min1 += 10;
if (min1>60) {
min1 = 0;
minutess.setCaptionLabel(“ВЫКЛ”);
} else {
minutess.setCaptionLabel(str(min1)+" Мин1");
}
}

Displaydata:

void Displaydata() {

switch(readIncome[0]) {
case 10:
minutess.setCaptionLabel(readIncome[1]+" Мин1.“); // No picture button
min1=readIncome[1];
break;
case 20:
//label(readIncome[1]+” Мин."); // ImageButton
//min=readIncome[1];
break;
case 30:
//P4.setText(“std2”+readIncome[1] ); // CheckBox
break;
case 40:
//inputPULI.setText("Bullet - "+readIncome[1] ); // Numberbox int
break;
case 70:
//inputNapryzenieKV.setText("Voltage - "+readIncome[1] ); // Numberbox float
break;
case 60:
Vin.setText("Voltage K.V - "+readIncome[1] ); // Textlabel
break;
case 50:
//CheckBoxuvum.setText("UV/UM - "+readIncome[1] ); // RadioButton
break;
default:
println(“DisplayData(): no case selected.”);
break; // technically not necessary, but I like my switches tidy
}
}

I haven’t understood your question

but this works:


import controlP5.*;

int min1 = 0;
int PUL;
float NapryzenieKV;
boolean strata=false;

ControlP5 cp5; 

Button minutess;
ImageButton button;
Numberbox inputPULI;
Numberbox inputNapryzenieKV;
RadioButton CheckBoxuvum;
CheckBox P4;
Textlabel Vin;
Button connection;
Button Send;

void setup() {
  size (1000, 600);
  setupUI();
}

void draw() {
  background(111);
  //cp5.draw();
}

public void setupUI() {
  cp5 = new ControlP5(this);
  PFont fontn = createFont("Times New Roman", 18);
  PFont p = createFont("Times New Roman", 18);

  ControlFont font=new  ControlFont(p);
  cp5.setFont(font);

  connection = cp5.addButton("toplug")
    .setCaptionLabel("ПУСК")
    .setPosition(387, 30)
    .setSize(150, 30);

  DropdownList serialPortsList = cp5.addDropdownList("Порт")
    .setPosition(130, 30)
    .setSize(150, 200)
    .setItemHeight(30)
    .setBarHeight(30);
  for (int i=0; i<40; i++) {
    serialPortsList.addItem("item "+i, i);
  }

  minutess = cp5.addButton("minutesss")
    .setCaptionLabel("ВЫКЛ")
    .setPosition(145, 100)
    .setSize(90, 25);

  Send = cp5.addButton("toapply")
    .setCaptionLabel("Apply")
    .setPosition(510, 370)
    .setSize(150, 30);

  Vin = cp5.addTextlabel("naprazhenie kondencatora")
    .setText("Voltage K.V")
    .setFont(p)
    .setColor(color(#00ffff))
    .setPosition(45, 320);

  CheckBoxuvum = cp5.addRadioButton("UV/UM")
    .setPosition(155, 360)
    .setSize(15, 15)
    .setColorActive(color(255))
    .setItemsPerRow(2)
    .setSpacingColumn(85)
    .addItem("+", 1)
    .addItem("-", 2);

  P4 = cp5.addCheckBox("std2")
    .setPosition(150, 190)
    .setSize(15, 15)
    .setItemsPerRow(1)
    .setSpacingColumn(30)
    .setSpacingRow(20)
    .addItem("Check", 2);

  inputPULI = cp5.addNumberbox("PUL")
    .setPosition(150, 220)
    .setSize(80, 30)
    .setColorValue(0xffffff00)
    .setFont(p)
    .setScrollSensitivity(1.1)
    .setDirection(Controller.HORIZONTAL)
    .setRange(1, 199)
    .setValue(3);
  Label labelinputPULI = inputPULI.getCaptionLabel();
  labelinputPULI.setFont(font);
  labelinputPULI.setColor(color(#00ffff));
  labelinputPULI.toUpperCase(false);
  labelinputPULI.setText("Bullet");
  labelinputPULI.align(ControlP5.LEFT_OUTSIDE, CENTER);
  labelinputPULI.getStyle().setPaddingLeft(-55);

  inputNapryzenieKV = cp5.addNumberbox("NapryzenieKV")
    .setPosition(150, 270)
    .setSize(80, 30)
    .setColorValue(0xffffff00)
    .setFont(p)
    .setScrollSensitivity(1.1)
    .setMin(25)
    .setMax(99)
    .setMultiplier(0.01)
    .setDirection(Controller.HORIZONTAL)
    .setValue(25);
  Label labelinputNapryzenieKV = inputNapryzenieKV.getCaptionLabel();
  labelinputNapryzenieKV.setFont(font);
  labelinputNapryzenieKV.setColor(color(#00ffff));
  labelinputNapryzenieKV.toUpperCase(false);
  labelinputNapryzenieKV.setText("Voltage");
  labelinputNapryzenieKV.align(ControlP5.LEFT_OUTSIDE, CENTER);
  labelinputNapryzenieKV.getStyle().setPaddingLeft(-45);

  textFont(fontn);
  {
    // button dimensions
    int w = 99;
    int h = 25;
    // test with generated images
    button = new ImageButton(140, 140, w, h, 
      new PImage[]{
      getImage(w, h, color(192, 0, 32 * 2)), // off
      getImage(w, h, color(0, 0, 32 * 3)), // 10
      getImage(w, h, color(0, 0, 32 * 4)), // 20
      getImage(w, h, color(0, 0, 32 * 5)), // 30
      getImage(w, h, color(0, 0, 32 * 6)), // 40
      getImage(w, h, color(0, 0, 32 * 7)), // 50
      getImage(w, h, color(0, 0, 32 * 8)), // 60
      });
  }
}

void mousePressed() {
  button.mousePressed(mouseX, mouseY);
  println(button.min);
}

// test images to represent loaded state images
PImage getImage(int w, int h, int c) {
  PImage img = createImage(w, h, RGB);
  java.util.Arrays.fill(img.pixels, c);
  img.updatePixels();
  return img;
}

public void minutesss() {
  min1 += 10;
  if (min1>60) {
    min1 = 0;
    minutess.setCaptionLabel("ВЫКЛ");
  } else {
    minutess.setCaptionLabel(str(min1)+" Мин1");
  }
}

void controlEvent(ControlEvent theEvent) {
  if (theEvent.isFrom(CheckBoxuvum)) {
    //myColorBackground = 0;
    print("got an event from "+CheckBoxuvum.getName()+"\t\n");
    // checkbox uses arrayValue to store the state of 
    // individual checkbox-items. usage:
    println(CheckBoxuvum.getArrayValue());
    int col = 0;
    for (int i=0; i<CheckBoxuvum.getArrayValue().length; i++) {
      int n = (int)CheckBoxuvum.getArrayValue()[i];
      print(n);
      if (n==1) {
        //myColorBackground += CheckBoxuvum.getItem(i).internalValue();
      }
    }
    println();
  }

  if (theEvent.isGroup()) {
    // check if the Event was triggered from a ControlGroup
    println("event from group : "+theEvent.getGroup().getValue()+" from "+theEvent.getGroup());
  } else if (theEvent.isController()) {
    println("event from controller : "+theEvent.getController().getValue()+" from "+theEvent.getController());
  }
}

// ---------------------------------------------------------------------------------------
// make a custom image button class
class ImageButton {
  // minutes is the data it stores
  int min = 0;
  // images for each state
  PImage[] stateImages;
  // which image to display
  int stateIndex;
  // position
  int x, y;
  // dimensions: width , height
  int w, h;
  // text to display
  String label = "ВЫКЛ";

  ImageButton(int x, int y, 
    int w, int h, 
    PImage[] stateImages) {
    this.x = x;
    this.y = y;
    this.w = w;
    this.h = h;
    this.stateImages = stateImages;
  }

  void mousePressed(int mx, int my) {
    // check the cursor is within the button bounds
    boolean isOver =
      ((mx >= x &&
      mx <= x + w) && // check horizontal
      (my >= y && 
      my <= y + h) ); // check vertical

    if (isOver) {

      min += 10;
      stateIndex++;

      if (min>60) {
        min = 0; 
        stateIndex = 0;
        label = "ВЫКЛ";
      } else {
        label = (str(min) + "Мин");
      }
    }
  }
  void draw() {
    // if the images and index are valid
    if (stateImages != null && stateIndex < stateImages.length) {
      image(stateImages[stateIndex], x, y, w, h);
    } else {
      println("error displaying button state image");
      println("stateImages: ");
      printArray(stateImages);
      println("stateIndex: " + stateIndex);
    }
    // display text
    text(label, x + 17, y + h - 8);
  }
}

//-----------------------------------------------------------------------------------------------------
//Displaydata:

void Displaydata() {

  int readIncome=100 ;  // FIX ????

  switch(readIncome) {

  case 10:
    minutess.setCaptionLabel("readIncome8"+" Мин1."); // No picture button
    // min1=readIncome[1];
    break;

  case 20:
    //label(readIncome[1]+" Мин."); // ImageButton
    //min=readIncome[1];
    break;

  case 30:
    //P4.setText(“std2”+readIncome[1] ); // CheckBox
    break;

  case 40:
    //inputPULI.setText( "Bullet - "  +"readIncome[1]" ); // Numberbox int
    break;

  case 70:
    //inputNapryzenieKV.setText("Voltage - "+readIncome[1] ); // Numberbox float
    break;

  case 60:
    Vin.setText("Voltage K.V - "+"readIncome[1]" ); // Textlabel
    break;

  case 50:
    //CheckBoxuvum.setText("UV/UM - "+readIncome[1] ); // RadioButton
    break;

  default:
    println("DisplayData(): no case selected.");
    break; // technically not necessary, but I like my switches tidy
  }
}
//

1 Like

I asked a question https://stackoverflow.com/questions/64726432/how-to-write-on-other-values-placed-after-the-operators-case here, got no answer. Correct everything and write for the numbers (DisplayData fix) 20,30,40,50,70. I myself don’t know how to ask (((I know the working code. Maybe I can upload the project here in full files so you can see?)

I can’t help you with that

basically here you have to evaluate all your controls and act:

See processing, menu file, examples, contributed libraries, controlP5…

if (theEvent.isFrom(CheckBoxuvum)) {
     //myColorBackground = 0;
} else if(theEvent.isFrom(........)) {
    // 
}  ................
.........