Variable based on instance of class (unsure of correct terminology)
in
Contributed Library Questions
•
6 months ago
TL;DR - when I call a new class, labels are being overwritten because they have the same name. How can I give a label a name dependent on the class instance?
Hi,
I come from the world of microprocessors so the whole class thing is still something of a mystery to me!
I'm trying to create a program that will have a few windows displaying fairly similar data (received from a pic). At the moment I have this:
I'm trying to create a program that will have a few windows displaying fairly similar data (received from a pic). At the moment I have this:
- void setup(){
- //set window dimensions
- size(700,300);
- controlP5=new ControlP5(this);
- l1_data = new Data(50, 70);
- l2_data = new Data(220, 70);
- }
- void draw(){
- background(125);
- l1_data.shapes();
- l2_data.shapes();
- }
- class Data{
- int X, Y = 0;
- Textlabel name, l1, l2, l3, N;
- Data(int tempX, int tempY){
- X = tempX;
- Y = tempY;
- stroke(255);
- fill(80);
- rect(X,Y,100,Y+100);
- name = controlP5.addTextlabel("name_label","Distro 1",X+2,Y+2);
- l1 = controlP5.addTextlabel("l1_label","L1",X+2,Y+15);
- l2 = controlP5.addTextlabel("l2_label","L2",X+2,Y+30);
- l3 = controlP5.addTextlabel("l3_label","L3",X+1,Y+45);
- N = controlP5.addTextlabel("N_label","N",X+2,Y+60);
- }
- void shapes (){
- stroke(255);
- fill(80);
- rect(X,Y,100,Y+100);
- }
- }
I hope that makes sense.
Thank you for your time.
Tom
1