I have a file system like so:
sketch
- sketch.pde
builtins
- button.pde
Where sketch.pde is my main Processing sketch, and button.pde is an external file containing various classes.
How do I access the classes from button.pde? I'm guessing it's through an import but I don't know if it's different in Processing than in Java.
I tried looking for an answer by looking through various open-source Processing projects, but all of the files were in one place, so no imports were required.
EDIT:
Apparently basic importing is impossible in Processing.
I have a mini-question then: I have another file system:
sketch
- sketch.pde
- builtins
- button.pde
Can I access button.pde now? Or is it still impossible?
You can access the classes in button.pde by simply placing button.pde in the same folder as sketch.pde.
For example, let's say button.pde contains a class called RedButton. As long as you have a folder called sketch/ with sketch.pde and button.pde inside it, you can say RedButton rb = new RedButton(); in sketch.pde and you will have created a new instance of the RedButton class.
Are you using the Processing IDE or are you using the command line tool to launch your project? If you are using the IDE, you will just want to see that sketch.pde and button.pde are visible as tabs in the same project when you open it. Hope this helps!
Edit: Mitchell's answer below shows that this is possible. Go read that answer!
One option is to use Processing as a Java library. You could then write some code that you export as a .jar file, which you could then drag onto your sketch.pde Processing editor and import the classes. In other words, you could create your own library that you then use in the Processing editor.
Another low-tech option is to copy the classes you want to use from button.pde into new tabs in sketch.pde.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With