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.
Page Index Toggle Pages: 1
Classes in tabs (Read 1661 times)
Classes in tabs
Apr 27th, 2005, 10:02pm
 
Is it possible to put classes in tabs, and if so, what is the correct way of doing it? I've tried splitting up code that works in a single tab and I get an error which makes little sense to me (not being very familiar with java yet).

Example:
main sketch tab:
Code:
public class ClassInTabTest extends PApplet {

public void setup() {
ClassInATab classInATab=new ClassInATab();
}
}


second tab:
Code:
 public class ClassInATab{
ClassInATab(){
System.out.println("ClassInATab constructed");
}
}


produces the error:
Quote:
java.lang.IllegalAccessException: Class processing.core.PApplet can not access a member of class ClassInATab with modifiers ""
java.lang.IllegalAccessException: Class processing.core.PApplet can not access a member of class ClassInATab with modifiers ""

     at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:57)


I recognise that this is almost certainly a result of a lack of understanding of the ways of java classes on my part.

edit: I should mention that this error only occurs when in Java mode.
Re: Classes in tabs
Reply #1 - Apr 28th, 2005, 2:08am
 
the error you were gettings is because the constructor in your second class needs to be "public", meaning:
Code:
public class ClassInATab{ 
public ClassInATab() {
System.out.println("ClassInATab constructed");
}
}

however, classes in additional tabs are just embedded into the main class that's defined in the first one. this is so that the rest of them still have access to all the processing functions (line, fill, etc).

in java mode, however, this won't work, because the class is already closed off, so after fixing the problem above, you're just gonna confuse the preprocessor.

the only way to make classes that are *outside* the main applet class is to create a .java file, which will not be preprocessed at all. so when you make a new tab, add .java to the name, telling processing to just read the code as straight java.

all that said, the better way to do it is to take the first tab out of java mode, and things should work fine. assuming you don't have a problem with ClassInATab being an inner class.

fwiw, there's not much use for java mode anymore, since import statements now work properly.
Re: Classes in tabs
Reply #2 - Apr 28th, 2005, 3:42pm
 
Thanks Smiley
Re: Classes in tabs
Reply #3 - May 13th, 2005, 10:45pm
 
hi, i also tried with classes in tabs.  what's wrong here?  using p90 on osX.3.7

//SKETCH
void setup() {
 TestColor ttest= new TestColor();
}

//TAB: testclass.java
import processing.core.*;
public class TestColor extends PApplet {
 public TestColor() {
   print(random(20));
   color nogo;
 }
}

error...
Type "color" was not found.

tia/rF
Re: Classes in tabs
Reply #4 - May 13th, 2005, 11:12pm
 
this is not a bug.

classes in tabs are not channeled thru the preprocessor. so you'll lose all it's translations from pde syntax to java syntax. one of these translations is that "color" becomes "int".

all things it does:
color  ->  int
float 0.0  ->  float 0.0f  (add f at the end)
#FF00FF  ->  0xFFFF00FF  (# becomes 0xFF)

see here for more information:
http://processing.org/discourse/yabb/YaBB.cgi?board=Integrate;action=display;num=1106256315;start=48#48

F
Re: Classes in tabs
Reply #5 - May 14th, 2005, 12:33am
 
not entirely true. only files with a .java extension are not parsed. if you write a class definition in a new tab, but use the default .pde extension, you can use any Processing syntax.

So not:
Code:

//TAB: testclass.java
import processing.core.*;
public class TestColor extends PApplet {
public TestColor() {
print(random(20));
color nogo;
}
}


Instead:
Code:

//TAB: testclass
class TestColor {
TestColor() {
print(random(20));
}
}
Re: Classes in tabs
Reply #6 - May 14th, 2005, 1:02am
 
yep. right ... that's what i meant in regard to the previous post. sorry for being unclear and thanks for correcting.

F
Re: Classes in tabs
Reply #7 - May 14th, 2005, 6:26am
 
I've just successfully made use of this in a mini-test project where I designed a series of draggable object classes, and used the java interface, extends and implements keywords... while keeping hold of all of processing's functionality.

http://mkv25.net/index.php?item_id=102
Page Index Toggle Pages: 1