how to instantiate a class from within a class?
in
Programming Questions
•
2 years ago
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:
- class InterfaceBuilder {
- //fields
- Button b;
- ControlP5 controlP5;
- //constructor
- InterfaceBuilder() {
- controlP5 = new ControlP5(this);
- for (int i = 0; i<8; i++) {
- controlP5.addButton("button" + (i+1), 200, i*100, 0, 100, 20);
- }
- }
- // function buttonA will receive changes from
- // controller with name buttonA
- public void buttonA (int theValue) {
- println("a button event from buttonA: "+theValue);
- myColor = theValue;
- }
- //triggered when button is clicked
- public void controlEvent(ControlEvent theEvent) {
- println(theEvent.controller().name());
- }
- }
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
1