Eclipse with new Processing 3 - Can't run PApplet as Applet

Hey there,

I'm experiencing some strange issues and would like to ask if anybody else has this: Since Processing 3 I can't run any PApplet from Eclipse anymore (no additional plug-ins, just following Daniel Shiffmans Tutorial). I already tried to manually add the run configuration, but this doesn't work neither.

I should add that it still works if I import the Processing 2 core.jar.

Answers

  • edited September 2015 Answer ✓

    It took me a while to do this as well. Link to Processing 3 core.jar and in Eclipse run as Java application.

    The reason is that PApplet no longer inherits from java.awt.Applet, a windowed component.

    import processing.core.PApplet;
    import processing.event.KeyEvent;
    import processing.event.MouseEvent;
    
    public class FooWinTest extends PApplet {
    
        // Run this project as Java application and this
        // method will launch the sketch
        public static void main(String[] args) {
            String[] a = {"MAIN"};
            PApplet.runSketch( a, new FooWinTest());
        }
    
        // The rest is what you would expect in the sketch
    
            int x, y;
    
        public void settings(){
            size(100, 100);     
        }
    
        public void setup() {
            // Other setuo code here
        }
    
        public void mouseMoved(){
            x = mouseX;
            y = mouseY;
        }
    
        public void draw() {
            background(0);
            ellipse(x, y, 10, 10);
        }    
    }
    
  • edited September 2015

    Moved to last post

  • Ah, I should probably have read the release notes. And btw this is way better than before! Thanks

  • fryfry
    edited September 2015

    That's messier than necessary; you only need to add this:

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

    Or if you want to be tricky (and have Eclipse refactoring work if you rename the sketch)

    static public void main(String[] args) { PApplet.main(YourSketchName.class.getName()); }

    The easiest way to move to Eclipse is to use Export to Application and look at the Java file(s) it creates. (In that version you'll also see other things that happen behind the scenes, like how 'args' are preserved if those are used in your sketch.)

    And for what it's worth, everything described here hasn't changed at all between 2.0 and 3.0.

Sign In or Register to comment.