Reputation: 25
I am trying to use this SDK (for IntelRealSense Cameras) written in Processing in my Java code. What I did was I took the java source code and made a project with it. So I can run processing sketches directly from my Intellij Java environment using the Processing library.
My question is, can the classes that extend the PApplet
class and show the sketches interact with other classes in the Java code ( that are not PApplet
s )? For example, can I create a Main
class to launch both the PApplet
sketch and a vanilla Java program as well with them being able to communicate?
The goal is to to integrate this PApplet
source code into an existing Java project as a module that can transmit information.
All in all, my objective is to : Run concurrently the PApplet
and my Java program and transmit the camera values from the PApplet
to my Java Classes.
Is it possible? I mean Processing is Java so It should be, right?
Thank you
Upvotes: 1
Views: 792
Reputation: 42174
The short answer to your question is yes it's possible.
Shameless self-promotion: here is a tutorial on using Processing from Java.
I recommend you read through that, but in summary, you want to do something like this:
import processing.core.PApplet;
public class MySketch extends PApplet{
public void settings(){
size(500, 500);
}
public void draw(){
ellipse(mouseX, mouseY, 50, 50);
}
public void mousePressed(){
background(64);
}
public static void main(String[] args){
String[] processingArgs = {"MySketch"};
MySketch mySketch = new MySketch();
PApplet.runSketch(processingArgs, mySketch);
// call whatever Java code you want
}
}
Note that the main()
method does not have to be in the same class that extends PApplet
.
This is all "just" Java, so anything that's valid in Java, is valid in a Java program that uses Processing as a Java library.
Upvotes: 3