3

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?

7
  • Are you asking about Java or Processing? Jan 18, 2017 at 1:44
  • @TimBiegeleisen Processing. TBH, I put the Java tag in mainly because no one would answer if I didn't. I can get rid of it if you want. The languages are similar, anyway.
    – Qwerp-Derp
    Jan 18, 2017 at 1:45
  • To be honest, no one might answer even with the Java tag. But here, have an upvote. Jan 18, 2017 at 1:46
  • @ScaryWombat I looked at it for a while, and apparently there isn't a solution - the devs of Processing said that imports for Processing wasn't going to happen, for some strange reason.
    – Qwerp-Derp
    Jan 18, 2017 at 1:49

2 Answers 2

5

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!

1

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.

9
  • So it's impossible to have multiple folders in a Processing project? That's disappointing.
    – Qwerp-Derp
    Jan 18, 2017 at 2:43
  • @Qwerp-Derp Processing was designed to be dead simple. If you need something more complicated, use eclipse. Jan 18, 2017 at 2:46
  • I might also have a sub-question. Can I add it on to my original question?
    – Qwerp-Derp
    Jan 18, 2017 at 2:55
  • @Qwerp-Derp I don't understand how this is such a deal-breaker. What exactly is your end goal? And if you have a follow-up question, you should probably just post it in its own new question. Jan 18, 2017 at 2:58
  • Yeah you're right, it was kind of an exaggeration. I can probably continue, it's just going to be a pain in the butt.
    – Qwerp-Derp
    Jan 18, 2017 at 2:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.