Usage class from .java file - is there a full doc for that?

edited March 2014 in How To...

Ok, I have some problem with use of tab with pure .java file. I know that's possible, but I can't get it to work.

The code:

main tab:

import processing.core.Foo;
Foo bar;

void setup() {
}

void draw() {
}

tab called Foo.java:

package processing.core;
import java.io.Serializable;
import processing.core.PApplet;

public class Foo implements Serializable {
}

The error I get:

The package processing.core.Foo does not exist.

The Foo.java file is in the sketch folder, along with the main file (which is called fjlea.pde, so no conflict here).

I tried to put the Foo.java in the ./code directory, as well as in the "sketchbook"/libraries - also without success.

How to get it to work? Is there any doc that describes the procedure?

Tagged:

Answers

  • edited March 2014 Answer ✓

    Here's a simple example:


    "Sketch.pde":


    // forum.processing.org/two/discussion/3677/
    // usage-class-from-java-file-is-there-a-full-doc-for-that
    
    void setup() {
      size(600, 400, JAVA2D);
      smooth(4);
      noLoop();
      clear();
    
      rectMode(Foo.MODE);
    
      fill(#0080FF);
      stroke(#FF0000);
      strokeWeight(3);
    
      new Foo(this).drawBox();
    }
    


    "Foo.java":


    import processing.core.PApplet;
    
    class Foo {
      static final int GAP = 15;
      static final int MODE = PApplet.CORNER;
    
      final PApplet p;
    
      Foo(PApplet pa) {
        p = pa;
      }
    
      void drawBox() {
        p.rect(GAP, GAP, p.width - GAP*2, p.height - GAP*2);
      }
    }
    

  • Holy!

    By reducing your good sketch to mine line by line I found, that the only problem was that I had pointless line:

    package processing.core;
    

    which caused problems ;)

    Many thanks!

  • Yes, Processing doesn't support package declarations...

Sign In or Register to comment.