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 › Running a PApplet in a non-static way
Page Index Toggle Pages: 1
Running a PApplet in a non-static way? (Read 316 times)
Running a PApplet in a non-static way?
Apr 8th, 2009, 10:24am
 
Hi,

I'm currently running my extended PApplet (Visualiser extends PApplet) with the following code:

public static void main(String[] args){
     PApplet.main(new String[] {"visualiser.Visualiser"});
}


However, I would now like to integrate it with other non-processing Java code.  I would like my Visualiser as an object stored in another class, so the static PApplet.main(String[] args) method is obviously not going to cut it.  A new instance of the Visualiser that I have no handle/reference to isn't useful.

I had assumed the method run() in PApplet was the way to do this, like so:


PApplet papplet = new papplet();
papplet.run();


However, this is just running briefly before quitting with no PApplet on screen; a Java app bounces in my Dock a few times and quits.

The method init() also doesn't seem to offer the functionality I'm looking for; it runs a persistent Java app, but, alas, no PApplet appears.

I thought rather than blindly groping through more methods to try and find the one I'm after I'd ask.  Does a method exist that does what I'm after?

I also realise that run() or init() may well be the methods I'm looking for, but that I've been stupid and forgotten something important about threads or similar and consequently haven't wrapped the method calls in the correct code.

Many, many thanks in advance for any help!
Stephen
Re: Running a PApplet in a non-static way?
Reply #1 - Apr 8th, 2009, 11:17am
 
Without a web page, you will have to create a place for your PApplet to hang out. In this case a Frame/JFrame.

http://dev.processing.org/reference/core/javadoc/processing/core/PApplet.html
Page Index Toggle Pages: 1