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.
IndexProcessing DevelopmentLibraries,  Tool Development › napplet: Embedded & windowed sub-sketches (v0.3.0)
Pages: 1 2 3 
napplet: Embedded & windowed sub-sketches (v0.3.0) (Read 14975 times)
napplet: Embedded & windowed sub-sketches (v0.3.0)
Apr 27th, 2010, 10:24am
 
Update 24 May 2010:  Version 0.3.0.  Mousewheel support, nested napplets, and other goodies.  See wiki/changelog at github for more details.

Update 6 May 2010:  Windowed napplets!  Version 0.2.0 is now up for download and supports windowed napplets as well as the old embedded ones.  Windowed napplets function just like embedded napplets with the same easy-to-use code structure, etc.

Currently the library supports creation and destruction of windowed napplets, with the option of allowing the user to close a window (and kill the napplet) with the usual window controls (e.g., the "X" button on Windows, etc.)  

There's no support as yet for resizing windows (I'm working on it.)

About

napplet is a lightweight library that allows you to "embed" one Processing sketch inside another.  This is potentially useful for a lot of things:
  • displaying data in different ways within the same window without having one display muck up another
  • creating a "control panel" in a portion of a sketch with buttons, etc. that control behavior elsewhere.
  • importing an existing sketch into a new one (source code transfers easily).


The library is available for download here.  Source code can be found here.

The API and coding is straightforward; an embedded sketch is simply enclosed in its own class that extends the NApplet class (which itself extends PApplet).  The NApplet class contains setup() and draw() methods, global variables, etc, and in pretty much all ways behaves like a standalone PApplet (i.e., sketch).

To create and display NApplets, you simply create a NAppletManager object in the setup() method of the main sketch, and call NAppletManager.createNApplet() to create each sub-sketch and tell it where to draw in the main sketch.  The NAppletManager then handles everything else "behind the scenes".

As an example, here's a demo that runs eight of the example sketches that come with Processing.  I wrote this demo in the PDE.  Here's the code for the main sketch:

Code:
import napplet.*;

PFont mainFont;

void setup() {
 size(800, 400);
 mainFont = loadFont("ArialMT-18.vlw");
 textMode(SCREEN);
 textAlign(CENTER, TOP);
 
 NAppletManager nappletManager = new NAppletManager(this);

 nappletManager.createNApplet("Scrollbar", 0, 0);
 nappletManager.createNApplet("Pattern", 200, 0);
 nappletManager.createNApplet("Convolution", 400, 0);
 nappletManager.createNApplet("Animator", 600, 0);
 nappletManager.createNApplet("BouncyBubbles", 0, 200);
 nappletManager.createNApplet("FireCube", 200, 200);
 nappletManager.createNApplet("Tickle", 400, 200);
 nappletManager.createNApplet("UnlimitedSprites", 600, 200);
}

void draw() {
 background(50);
 
}


Each sub-sketch was contained in its own tab in the PDE (you can see the source at the openprocessing.org link above).  All of them were created by cutting-and-pasting the source code straight from the standalone sketches (and copying any necessary files from the sketch's data/ folder, of course.)  The only change made to any of the sketches was adjusting the size() to fit in the gallery.

NApplet sketches have access to all of the variables and methods of the parent sketch, so they can potentially be parts of a larger application.

Let me know if you find this at all useful.
Re: napplet: Multiple "embedded" sketches in one.
Reply #1 - Apr 27th, 2010, 11:00am
 
What a clever, well executed and simple solution to showing multiple sketches.

Well done Smiley
Re: napplet: Embedded and windowed sub-sketches.
Reply #2 - May 6th, 2010, 11:13am
 
Not sure what the protocol is, but I've added (basic) windowing support to napplet.  I thought that merited a bump, since it potentially makes it useful to more people.
Re: napplet: Embedded and windowed sub-sketches.
Reply #3 - May 7th, 2010, 12:57pm
 
excuseme, napplet seems to work only on intel-based mac with java 1.6

I have a PPC with java 1.5 .... there is no possibilities to use napplet?
Re: napplet: Embedded and windowed sub-sketches.
Reply #4 - May 7th, 2010, 1:38pm
 
PierG wrote on May 7th, 2010, 12:57pm:
excuseme, napplet seems to work only on intel-based mac with java 1.6

I have a PPC with java 1.5 .... there is no possibilities to use napplet

Hmmm, I'm not exactly an expert on this, but it might be because I compiled it with 1.6.  I'll see if I can get it to compile with 1.5 or 1.4 and then upload a new .zip.
Re: napplet: Embedded and windowed sub-sketches.
Reply #5 - May 7th, 2010, 11:53pm
 
hi smitty,
inside your build.xml file you can add attribute target to the javac tag (line 119), currently it looks like this:
Code:

<javac srcdir="${src}" destdir="${bin}" source="${javaVersion}">

and after adding attribute target it should look like this
Code:

<javac srcdir="${src}" destdir="${bin}" source="${javaVersion}" target="${javaVersion}">


whereas property ${javaVersion} holds the java version that should be used to compile your project. (in your build.xml file it is set to 1.5)
best,
andreas
Re: napplet: Embedded and windowed sub-sketches.
Reply #6 - May 8th, 2010, 8:23am
 
Thank you, sojamo!  I've been trying to figure out how to do that.

I've uploaded a new zip file to github that was targeted at java-1.4.2 (I think).  If someone gets a chance to try it, please let me know if it works or not.
Re: napplet: Embedded and windowed sub-sketches.
Reply #7 - May 9th, 2010, 7:13am
 
What an elegant solution!

A quick question: do the napplets share the same mouseX and mouseY as the main sketch, or are they relative to the napplets themselves? I assume the latter would be more useful in most of the cases, but what if I want to acces the "global" mouse coordinates in a napplet?
Re: napplet: Embedded and windowed sub-sketches.
Reply #8 - May 9th, 2010, 8:33am
 
Job wrote on May 9th, 2010, 7:13am:
What an elegant solution!

A quick question: do the napplets share the same mouseX and mouseY as the main sketch, or are they relative to the napplets themselves I assume the latter would be more useful in most of the cases, but what if I want to acces the "global" mouse coordinates in a napplet


Thanks for the kind words (everyone!)

NApplets do have their own mouseX and mouseY relative to their own position; the goal is for a NApplet to behave as much like a standalone PApplet as possible.

The parent's mouse position should be available through parentPApplet.mouseX and parentPApplet.mouseY.  (Along with all the other "global" variables of the parent.)

Or if for some reason that doesn't work, you could calculate it yourself with nappletX + mouseX, etc.
Re: napplet: Embedded and windowed sub-sketches.
Reply #9 - May 13th, 2010, 2:03am
 
Don't know why but I doesn't seem to work Sad

I'm really a beginner so I haven't much experience with libraries and so on..

it says: "StringIndexOutofBoundsException"

don't know what that means??

what do you I have to change?
Re: napplet: Embedded and windowed sub-sketches.
Reply #10 - May 13th, 2010, 8:58am
 
beginner_processing wrote on May 13th, 2010, 2:03am:
Don't know why but I doesn't seem to work Sad

I'm really a beginner so I haven't much experience with libraries and so on..

it says: "StringIndexOutofBoundsException"

don't know what that means?

what do you I have to change

Can you paste your code in  It could be a number of things -- considering how new this library is it could even be a bug in the library.  So, cutting and pasting the program that's giving you the error would be a big help, to you and to me. Wink
Re: napplet: Embedded and windowed sub-sketches.
Reply #11 - May 15th, 2010, 12:01pm
 
I've just downloaded the code and opened the file.. I've not even had the possibility to change something or study the code because I have no idea how to make it work..

When I'm right, it's a file that includes other processing files, but more I couldn't understand..

would be nice of you to help a total beginner but I could understand if you don't want to  Embarrassed Wink
Re: napplet: Embedded and windowed sub-sketches.
Reply #12 - May 16th, 2010, 5:12am
 
now I've studied the way it works and I've downloaded it.. but I think the problem is, where I have to place this files..

when I have a main file and other files. do i have to place the others in the main folder? or in the library folder?

is there a website about napplet? i haven't found one..

thank you..
Re: napplet: Embedded and windowed sub-sketches.
Reply #13 - May 16th, 2010, 1:57pm
 
beginner_processing wrote on May 16th, 2010, 5:12am:
now I've studied the way it works and I've downloaded it.. but I think the problem is, where I have to place this files..

when I have a main file and other files. do i have to place the others in the main folder or in the library folder

is there a website about napplet i haven't found one..

thank you..


It works the same way as other Processing libraries.  You should have a "libraries" folder in your Processing sketchbook folder (if not, make one.)  Take the "napplet" folder out of the zip file and put it in the libraries folder.

Then start (or restart) Processing and look under File -> Sketchbook -> libraries -> napplet -> examples to see the example sketches.

Re: napplet: Embedded and windowed sub-sketches.
Reply #14 - May 17th, 2010, 12:29am
 
thank you..

another question: is it possible to make the connection between these files. when I do something in one "frame" something changes in the other "frame".. ?

or are they independent?
Pages: 1 2 3