We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › using interfaces in processing
Page Index Toggle Pages: 1
using interfaces in processing (Read 493 times)
using interfaces in processing
Jan 30th, 2008, 5:23pm
 
Code:
  
interface test{
void testify();
//void testify(Porky p); // Why!?!? <------
void testify(String k);
}
class Porky implements test{
Porky(){};
void testify(Fudd p){
println("Fudd says "+p.say());
}
void testify(){

}
void testify(String p){
println("string "+p);

}
}

class Fudd{
Fudd(){}
String say(){
return "that's all folks";
}
}

Fudd k;
Porky p;
void setup(){
k=new Fudd();
p=new Porky();
}

void draw(){
p.testify(k);
}




I'm sorry if this has been covered before, but why can't i define a function signature in the interface that requires a class that is defined in the current sketch?
Re: using interfaces in processing
Reply #1 - Jan 30th, 2008, 6:45pm
 
Because processing wraps everything into an inner class I believe.

There is a way round it though, change the interface function definition to take an Object, and then cast it inside the function.
Re: using interfaces in processing
Reply #2 - Jan 30th, 2008, 8:42pm
 
As per JohnG, but another work around is by adding native .java tabs to your sketch and putting your classes/interfaces in those instead of in a .pde tab.  (you'll additionally want to specify public access where necessary, and probably pass a reference to the PApplet in the constructor)
Re: using interfaces in processing
Reply #3 - Jan 31st, 2008, 3:28am
 
Thanks guys!
Re: using interfaces in processing
Reply #4 - Jan 31st, 2008, 10:54am
 
Ok so i reorganised this to

a.pde
Code:

class Fudd{
Fudd(){}
String say(){
return "that's all folks";
}
void setThis(test e){
//e.testify("borgoborg");
//((Porky)e).oink();
}

}

Fudd k;
Porky p;
void setup(){
k=new Fudd();
p=new Porky();
}

void draw(){

// p.testify(k);
k.setThis(p);
}





and porky.java

Code:

public interface test{
void testify();
void testify(Object asd);
void testify(String zxc);
}

public class Porky implements test{
Porky(){};
void testify(Object qwer){
println("Fudd says "+((Fudd)qwer).say());
}
void testify(){

}
void testify(String qwert){
println("string "+qwert);

}
void oink(){
println("oink");
}
}




And that doesn't quite work.
Re: using interfaces in processing
Reply #5 - Jan 31st, 2008, 11:04am
 
Ok besides some silly package things, changing the functions in the java file to public access seems to work.
Page Index Toggle Pages: 1