How to import a Processing file into a Processing file?

1.6k views Asked by At

I am making a Java Processing project in Processing IDE and would like to spread it across multiple PDE (Processing Source Code) files.

I am unable to import Java Processing Source Code file as a Java class file using import.

config.pde

public int screenWidth = 750;

project.pde

import project.config;
// OR
import project.config.screenWidth;
// OR
import config;
// OR
import config.screenWidth;

returns The import project/config cannot be resolved. respectively.

Do I have to compile PDE files first? Can I set up the Processing IDE to do it automatically for every run?


TLDR;

Having this project folder:

|project
|--project.pde
|--config.pde

How do I use functions and variables from config.pde in project.pde?

1

There are 1 answers

0
micycle On BEST ANSWER

In general:

The Processing IDE may support multiple tabs but these do not behave like Java classes: every tab is a member of the same higher-level class behind the scenes. As a result, all members from all tabs share the same scope and a tab that declares a given primitive, object, method or class needn't be referenced when another tab accesses a member from it.

For this reason, declaring a member private in one tab will not reduce accessibility of it in other tabs; every declaration is effectively public, for they reside within the same outer-class scope.

import is only required when you wish to introduce and reference external libraries.

In your project:

Simply refer to screenWidth within the project.pde tab to access it. The same can be said for any methods you wish to reference between tabs.