TaT NetBeansProcessing

NetBeans for Processing users

0. Preface

From the Processing website:

Processing is an open source programming language and environment for people who want to program images, animation, and interactions. It is used by students, artists, designers, researchers, and hobbyists for learning, prototyping, and production. It is created to teach fundamentals of computer programming within a visual context and to serve as a software sketchbook and professional production tool. Processing is an alternative to proprietary software tools in the same domain.

Though Processing does rather good at providing an easy-to-use environment for creating all kinds of visual stuff, having a closer look quickly reveals that, under the hood, Processing actually 'nothing more' than some kind of wrapper around standard Java technologies, specifically the JDK tools and the applet technology, to ease access to these tools to those who aren't that familiar with doing Java development and/or want to learn to do visual programming before learning how to master such an environment.

However, knowing it's basically Java also doesn't hurt, and this way, considering using a more "sophisticated" IDE than Processings very own sketch development interface seems a somewhat simple task. There is an outline how to do this using Eclipse, and using NetBeans is same as straightforward at the very least.

1. Environment

There's not much to prepare actually:

  • Download the Processing package which can be found here; most of these distributions come with a JRE of their own which you won't eventually need however.
  • Have a recent Java Development Kit installed as this is a prerequisite at least for NetBeans.
  • Have a recent version of NetBeans installed on your machine; 6.5 is the current release at time of writing this.

If not done so already, do install the JDK and NetBeans according to the installation requirements of your system environment. As for Processing, do unpack the archive you downloaded to some folder on your hard drive, from now on referred to as $PROCESSING_HOME.


2. General considerations

In Processing, you use the "Processing Development Environment" (PDE) that comes with Processing (and can be started from $PROCESSING_HOME after unpacking the downloaded archive) to create sketches and easily run them from within that environment. Looking at the tooling from a PDE users point of view, it is little more than a well-crafted tool for doing straightforward graphics programming. From a Java users point of view, things are a little more (but not that much) complicated:

  • Code written in the PDE generally is code written to classes inheriting from a Processing base class PApplet, itself being a sub-class of standard Applet. Subsequently, In order to create sketches outside the PDE, you will have to write a class extending PApplet, overriding some methods it provides.
  • Along with the PDE, PApplet and several other classes belonging to the Processing system are provided as .jar files in $PROCESSING_HOME/lib.


3. A simple project

So overally working with Processing in NetBeans is rather straightforward:

  • Create an empty Java project (project type "Java Application" or "Java Class Library" in the "New Project" window). If you do create a Java Application, please un-check the "Create Main Class" option during project creation as we will not need this for this purpose.
  • Having created the project, navigate to its "Libraries" node in the "Project" view, right-click and choose "Add Jar/Folder". In the "Add Jar/Folder" window, navigate to $PROCESSING_HOME/lib and choose "core.jar" which contains the core Processing classes required for this basic example.
  • Having done so, create a new Java Class "Sketch" in the project and add the following code to it:



import processing.core.PApplet;

public class Sketch extends PApplet {

    @Override
    public void setup() {
        size(200, 200);
        stroke(155, 0, 0);
    }

    @Override
    public void draw() {
        line(mouseX, mouseY, width / 2, height / 2);
    }
}


As outlined before, the custom class "Sketch" does extend PApplet and override two of its methods, setup() which is used to get the Sketch window set up as desired, and draw() which continuously does redraw the applet / Sketch environment according to the code executed herein.

In order to run that example, you can use SHFT+F6 or the "Run File" command (right-click in the editor or on "Sketch.java" in the "Projects" window). Be sure not to try to run the project directly (i.e. using the "Run Main Project" arrow) as this will fail, lacking a class providing a main() method. Everything working well, you should then see the applet viewer coming up, having the Sketch applet working, allowing you to draw red lines from a "center" point to the current mouse arrow position when moving across the applet window:

Image:screen-sketch_TaT_NetBeansProcessing.jpg


4. Conclusions and Limitations

Processing is a rather simple way of getting into Applet and "graphics" / media programming using the Java language, and creating Processing sketches with NetBeans is not much more difficult than doing the same using the Processing Development Environment. The only limitation found so far is the absence of an easy-to-use applet exporter, this is where the PDE still might come in helpful.

5. Resources

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo