Your idea about having your editor GUI interact with the Processing GUI is... messy. And unreliable. GUIs are meant for human interaction, not automatic interaction, and there's usually a better way to do what you want.
The processing-java
program included in the Processing download can be run from the command line to compile and run Processing sketches. A Processing sketch is a bit more than just a source file, though-- it should be in a certain folder structure with some metadata. From an automatic perspective, the process goes something like:
- Have your editor create a folder called, for example,
Bubbles
inside your sketchbook folder.
- Have your editor create and fill a text file called, in this example,
Bubbles.pde
. It should be in the Bubbles folder alongside a file called sketch.properties
that contains information about the sketch. Check some sketches on your computer for its contents. Presumably you'd use FileWriter, etc.
Compile and run the newly created file. The command will be something like:
/path/to/processing-java --force --run --sketch=/path/to/sketchbook/Bubbles --output=/path/to/working/folder/Bubbles
--force
causes it to overwrite older versions of the compiled bytecode
--run
causes the compiled sketch to be executed after compilation
--sketch
specifies the name of the sketch to compile. This should be the path to the Bubbles folder, not the sketch itself
--output
specifies where to put the compiled bytecodes. This doesn't need to be anywhere in particular unless you wish to get at the executables later. You probably want to keep track of how big this working folder gets, as compiling tons of sketches will fill it up fast.
This is the shell command that needs to be run. To do this from your java app, you'd probably do something like
Runtime.getRuntime().exec(pjPath + "--force --run --sketch=" + bubblesPath + " --output=" + outputPath);
I've left out some details (the file writing/folder creation, etc) because that's somewhat specific to your app and can be found elsewhere on the internet. If you're on Windows, you'll need to adjust your paths accordingly (backslashes, drive letters, etc) as I've used the Linux conventions here.