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 › Processing static
Page Index Toggle Pages: 1
Processing static (Read 404 times)
Processing static
Nov 6th, 2007, 11:58pm
 
I find I have a lot of trouble trying to make static classes in Processing. A static class wont access any non-static component, which is weird. How come I cant do this:

static class Console
{
 String[] messages = new String[10];
 static void Init()
 {
   fontConsole = loadFont("LucidaConsole-10.vlw");
 }
}

loadFont isnt static so I cant use it. What the hell is that?
Re: Processing static
Reply #1 - Nov 7th, 2007, 12:28am
 
Any class you're creating is actually an inside class of a PApplet. Processing does some fiddling behind the scenes and wrapping all your code into one outer class.

So what your code eventually becomes is your inner clss which you're saying is static tying to access a member function of the parent class, which isn't.. and that makes no sense, so the compiler complains and says "no".
Re: Processing static
Reply #2 - Nov 7th, 2007, 5:08am
 
if "static" is need to be single-instance, the singleton pattern will be fit.
Page Index Toggle Pages: 1