Insert processing 3 into the swing

I am trying to integrate Processing 3 into a swing application, but since PApplet no longer extends the applet, I cannot immediately add it as a component.

Whatever the embedding of the Processing 3 sketch in Swing, this would be enough if I could just open the sketch in a separate window without a PDE.

+4
source share
1 answer

You can run a sketch from Java by extending PApplet and then using the function runSketch()to launch this PApplet. It will look something like this:

String[] args = {"MyPapplet "};
MyPapplet mp = new MyPapplet ();
PApplet.runSketch(args, mp);

public class MyPapplet extends PApplet {

  public void settings() {
    size(200, 100);
  }
  public void draw() {
    background(255);
    fill(0);
    ellipse(100, 50, 10, 10);
  }
}

, , , , . :

PSurfaceAWT awtSurface = (PSurfaceAWT)mp.surface;
PSurfaceAWT.SmoothCanvas smoothCanvas = (PSurfaceAWT.SmoothCanvas)awtSurface.getNative();

SmoothCanvas, .

+4

Source: https://habr.com/ru/post/1611414/


All Articles