class array ?
in
Programming Questions
•
1 year ago
Hello all,
I search an idea to named class like an array, because I need a lot of classes, may be thirty, may be more with a same familly name. And i don't want write the name and add a number for calling the class, calling the void...etc. I don't find a topic about that, may be is not possible?
I make an example with three classes and classical system,
but I should make something like that
for ( int i = 0 ; i < n ; i++ ) {
String a = "Object" ;
String classObject = a + (i+1) ;
if ( i+1 == 1 ) obj1 = new Object1() ;
}
Stan
I search an idea to named class like an array, because I need a lot of classes, may be thirty, may be more with a same familly name. And i don't want write the name and add a number for calling the class, calling the void...etc. I don't find a topic about that, may be is not possible?
I make an example with three classes and classical system,
but I should make something like that
for ( int i = 0 ; i < n ; i++ ) {
String a = "Object" ;
String classObject = a + (i+1) ;
if ( i+1 == 1 ) obj1 = new Object1() ;
}
Copy code
- Object obj ;
void setup()
{
size(300,300) ;
obj = new Object () ;
}
void draw()
{
background(0) ;
obj.display() ;
}
// class Call
class Object
{
int n ; // quantity of class must be open
Object1 obj1 ;
Object2 obj2 ;
Object3 obj3 ;
Object() {
// read the .txt with the info with quantity of class must be open
/*
String call[] = loadStrings("/Users/stanislasmarcais/Desktop/ROMANESCO/Romanesco_Beta/TestInterface/importationProgShape/importationProgShape1a/data/ClassShape.txt");
for (int i = 0 ; i < call.length ; i++ ) {
String [] cut = split(call[i], ':' ) ;
String nObject = cut[1] ;
n = int(nObject) ;
}
*/
int call = 3 ;
n = call ;
for ( int i = 1 ; i <= n ; i++ ) {
if ( i == 1 ) obj1 = new Object1() ;
if ( i == 2 ) obj2 = new Object2() ;
if ( i == 3 ) obj3 = new Object3() ;
}
}
void display()
{
text ("Total class Objects: " + n, 20, 20 ) ;
for ( int i = 1 ; i <= n ; i++ ) {
if ( i == 1 ) obj1.display() ;
if ( i == 2 ) obj2.display() ;
if ( i == 3 ) obj3.display() ;
}
}
}
// class called
class Object1
{
Object1 () {}
void display() { text("First class object", 20 , 40) ; }
}
class Object2
{
Object2 () {}
void display() { text("Second class object", 20 , 60) ; }
}
class Object3
{
Object3 () {}
void display() { text("Third class object", 20 , 80) ; }
}
Stan
2