Loading...
Logo
Processing Forum
Hello,

I am using the controlP5 library to create a user interface. Since i try to train myself in writing nicely structured OO code i would like to instantiate the controlP5 class from y own interfaceBuilder class as following:

Copy code
  1. class InterfaceBuilder {
  2.     
  3.   //fields
  4.   Button b;
  5.   ControlP5 controlP5;
  6.   
  7.   //constructor
  8.   InterfaceBuilder() {

  9.     controlP5 = new ControlP5(this);
  10.     
  11.     for (int i = 0; i<8; i++) {
  12.       controlP5.addButton("button" + (i+1), 200, i*100, 0, 100, 20);
  13.     }
  14.   }

  15.   // function buttonA will receive changes from 
  16.   // controller with name buttonA
  17.   public void buttonA (int theValue) {
  18.     println("a button event from buttonA: "+theValue);
  19.     myColor = theValue;
  20.   }

  21.   //triggered when button is clicked
  22.   public void controlEvent(ControlEvent theEvent) {
  23.     println(theEvent.controller().name());
  24.   }
  25. }

When running this code i get the error message that "the constructor ControlP5(joystick.InterfaceBuilder) is undefined"

(joystick is the name of my program). 

When i create an controlP5 object in the setup loop it works fine, but i would like to create a class around it. What is wrong with the above code?

thanks in advance!

jorrit

Replies(4)

Your "this" is different in the two contexts. In the setup loop, I believe the "this" points to a PApplet.

You should modify your InterfaceBuilder class so that it takes the "this" pointer from the setup loop, and passes it on to  ControlP5's constructor:

void setup(){
...
my_interface = new InterfaceBuilder(this);
...
}

class InterfaceBuilder{
...
InterfaceBuilder(PApplet setups_this){
...
controlP5 = new ControlP5( setups_ this);
...
}

Hope that helps!
that did it! 
Thanks a lot!
This one will go in the FAQ (if not already there...), for sure!
I did not get an error but the program doesn't seem to work...


cheers