Can I launch an instance of Processing inside of a control on a sketch?

Is it possible to put some kind of a control on a sketch and launch an instance of Processing in that control? I would also like the user to be able to resize a move it. If this is not possible, is there a browser control that can be placed in s sketch and launch ProcessingJS in this browser control?

Answers

  • Interesting question. What have you tried so far?

  • edited September 2015

    I looked at all of the commands (https://processing.org/reference/) and determined that only one even comes close to being useful for this. The launch() command. However, as was expected, this opens a new instance of Processing totally outside of the sketch. As for controls to act as containers, I found none. I also do not find a browser control, so cannot even try ProcessingJS this way.

    windows 8 Processing 3.0b6

    (By the way, on the intro screen and Help/About Processing, at the top is displayed "3.0 alpha 3.1 bi", but on the window title is displayed "Processing 3.0b6".)

  • edited September 2015

    Also, in C#, I can create a child window inside a parent window, then launch an EXE inside of the child window. (I did not actually verify that Processing can be launched this way, but many, many EXEs can.) So, I mostly likely can accomplish my final goal via C#. But really, I want to do the entire application with Processing.

    I also found at this site how to embed multiple instances of Processing in a Java application using Eclipse. But really, I don't want to install and learn Eclipse, either.

  • I found here information about the javax.swing class JWindow that might lead to a solution. I see that a child component can be added to an associated contentPane, so this at least is on the right track. I have never used any of the swing components, so I'll need to do some reading and experimenting.

  • Maybe you're looking for a JFrame. Here, I found this link, it is old however, so may not work with current versions of processing.

  • edited September 2015

    Thanks Ater. I am already checking JFrame and JApplet. Because using the EXE would result in Windows―only solution, I am looking at embedding the Processing file (core.jar) that would make my final distributed app launch my chosen embedded version of Processing as a java file, making it OS agnostic, and giving me control over the version of Processing that the end―user sees.

  • @regitmail: i have an app which launches 100 instances of PApplet adding them to 100 Frames which can be resized or moved by user...I have done that with eclipse but also with processing. But i am not sure wether is it what you want because you are speaking about JApplet

  • @regitmail I don't quite understand what you are asking, but at the same time I think I do... do you want:

    a) To run a processing sketch that can open up new sketch windows b) Run a processing sketch that when you open it, it opens another Processing.exe c) None of what I previously mentioned.

    If its either a or b I know how to do those, so please tell me if I can be of help.

  • Techwiz777, I want the end user to launch a file. When it opens, there will be a panel occupying a portion of the window. Processing will be running in that panel, and the user can work with Processing. Near the panel will be an interactive display that will enable the user to have a visualization of changes in variables over time. Next to this interactive display will be Processing's graphics output of the code that is produce when the user runs the code. I am confident that I can do this by writing a Java app that embeds processing.core, and then coding a Processing UI. But I think it would be easier to have Processing actually running in the panel rather than for me to write a new UI for it. However, I actually want to avoid using Java and do this project all from Processing.

  • @regitmail:: when you say "interactive display" do you mean a real device display, different from the init one? - When you say "next to it" is it a third physical device??? - Can you post an "image" showing the whole stuff?? ?

  • Here is a PNG link that contains an example layout. And here is a PDF link.

  • ok, i begin to understand...but only begin!

    1.so you want 3 "panels" but not physical displays? yes?No? 2.first one, where i see code in your picture, must be as in the picture, i mean: the user SEE the code and can change it real time? yes?No?(it s a gui with sliders && buttons && values...) 3. second one uses the new values in order to modify some app according to the new values from user? 4.third one is only the result of the first one

    let us take some simple example first one== background(0); it shows a black screen on third one and on the second one the new value (0) means that an image (clickable or...) is displayed from a PImage[], img = [0]

    is it that???

  • You are closer, akenaton. yes, three panels that are laid out on a window, not separate display devices. I think you are asking if this was meant to be 3 separate monitors; no, it is not.

    from left-to-right,

    first panel is simply Processing running. (Somehow I need to get the Processing app embedded so it can run in this panel, just like it runs as a stand-alone application, except the graphical output is not in a new, independent window, but rather is in the third panel.)

    second panel is designed by me, the developer. The actual content will vary depending on a selection by the user. However, this panel is associated with the code of the first panel, line-by-line. For example, if there is a loop, this second panel will display some graphical indication of the loop value, such as a series of dots that go from left-to-right. So, if there are 10 steps in the loop, there will be a row of 10 dots. The user can click on any dot and the display (third panel) will display the output at that specific step. So at this point, the code is not free-running, but can be stepped through, either forward or backwards.

    third panel is simply the graphical output of the first panel. Or, if the user has clicked in the second panel, the graphical output is displayed for that specific step. This third panel is the normal graphical output of a sketch, but directed to this panel instead of opening in a stand-alone window as happens when you run a Processing sketch.

    Also, I would like the user to be able to run the code and then interact with values in real time and the output (in the third panel) updated in real time. The interaction will be as in R language. That is, click and hold down the left mouse button on a value and then slide left or right to decrement/increment the value.

    The main purpose of the app is to enable the end user to explore, by simple interactions, some specific code that is provided, and to have real-time feedback on how the changes that are being made affect the graphical output.

    As a secondary purpose, the end user can modify the provided code and save as a new Processing sketch (or just save the provided code as a sketch), or, the first panel can be used by the end user to simply play with Processing but without anything displayed in the second panel (because the second panel contents are designed by the developer to be relevant to the first window code.)

    I suspect that some of these features can be implemented by modifying the Processing IDE classes, or by adding some new classes.

  • edited September 2015

    @ regitmail::::: ok, not so difficult; i make a try asap...i dont remember wether there are P5 libs for that but if they are, they probably use JFrame in some or another way.

    PS: at the beginning, yet you spoke about "browser" && js, can you be more precise???

  • edited September 2015

    @akenaton, thank-you for your interest. As for the original post that mentioned browser object and embedding or launching an exe, those ideas are no longer relavent.

  • ok, as soon as i can (!!!!!) i post there some simple code to do that

  • edited September 2015

    @regitmail::: is something like that, which i have coded too quickly i am afraid!

    the first screen shows possibility of interaction (simple mouseX, but could be what you want with buttons && sliders); second screen interacts with the first one according to user and also of course you can add here what you want in its class); third screen shows first one without changing any value.

                import processing.core.*;
    
    
                 import javax.swing.*;
                 import java.awt.Dimension;
                 import java.awt.BorderLayout;
                import java.awt.event.*;
                import java.io.File;
                import java.io.IOException;
    
    
                int mX;
                int mY;
                int ts;
                int bg;
    
                AppletClass1 ap;
                AppletClass2 standard;
                FrameClass windo;
    
    
    
                void setup(){
                  size(500,600);
                  background(255);
                  String tx = "je réagis";
                  String txstandard = "interagissez";
                  ts = 12;
                  bg=187;
                   ap = new AppletClass1(500,600,bg, tx);
                    windo = new FrameClass(600,70,400,600,ap);
    
                 windo.create();
                 standard = new AppletClass2(500,600,255, txstandard);
    
                  windo = new FrameClass(600,400,500,600,standard);
                  windo.create();
                  fill(0);
                   text(txstandard,100,100);
    
                }
    
                void draw(){
    
                  fill(0);
                  ellipseMode(CENTER);
                  ellipse(mouseX,mouseY,1,1);
                  mX= mouseX;
                 mY= mouseY;
                 int value = (int) map(mX,0,600,12,48);
                 ts = value;
                 if(mouseX !=pmouseX){
                 bg = bg+value;
                }
    
                };
    
                //SECOND SCREEN second class
    
                protected class AppletClass1 extends PApplet{
    
                int sizeX,sizeY, bg2;
                String leTxt;
    
                  AppletClass1(int sX, int sY, int back, String t){
    
                sizeX = sX;
                sizeY = sY;
                 bg2 = back;
                 leTxt = t;
    
                }
    
    
    
                public void setup(){
                 size(sizeX,sizeY);
                background(bg);
    
    
    
                };
    
    
                public void draw(){
    
                  background(bg);
                  textSize(ts);
                 text(leTxt, 100,100); 
    
    
                };
    
    
    
                 @ Override
                public void start(){
    
    
                }
                 @ Override
                public void stop(){
    
                  this.noLoop();
    
    
                }
    
                };
    
    
                //SCREEN 3, third class
    
                protected class AppletClass2 extends PApplet{
    
                int sizeX,sizeY, bg2;
                String leTxt;
    
                 AppletClass2(int sX, int sY, int back, String t){
                sizeX = sX;
                sizeY = sY;
    
                 bg2 = back;
                 leTxt = t;
    
    
    
                }
    
    
    
                public void setup(){
                 size(sizeX,sizeY);
                background(bg2);
                fill(0);
                 text(leTxt, 100,100); 
    
    
    
                };
    
    
                public void draw(){
    
    
    
    
                };
    
    
    
                 @ Override
                public void start(){
    
    
                }
                 @ Override
                public void stop(){
    
                  this.noLoop();
    
    
                }
    
                };
    
    
                //CLASS FOR J FRAMES
    
    
                protected class FrameClass extends JFrame {
    
                  int xPos, yPos, wid, heigh;
                  PApplet applet;
                  JFrame frame;
                  JPanel panel;
                   private WindowAdapter windowAdapter;
    
    
                  FrameClass(int _posX, int _posY, int w, int h, PApplet ap) {
                    xPos =_posX;
                    yPos = _posY;
                    wid = w;
                    heigh= h;
                    applet = ap;
    
    
                  }
    
    
                  public void create() {
    
                    frame = new JFrame("Ecran");
                      this.frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
                    applet.init();
                    applet.start();
    
    
                   frame.addWindowListener(new java.awt.event.WindowAdapter() {
                    @ Override
                    public void windowClosing(java.awt.event.WindowEvent windowEvent) {
    
                      applet.stop();
    
                       frame.dispose();
    
                    }
                });
    
                    panel = new JPanel();
    
                    panel.setLayout(new BorderLayout());
                    panel.add(applet, BorderLayout.CENTER);
    
    
                    panel.setPreferredSize(new Dimension(wid, heigh));
    
    
                    this.frame.setSize(wid, heigh);
                    this.frame.setLocation(xPos, yPos);
                    this.frame.setDefaultLookAndFeelDecorated(true);
    
                    this.frame.setResizable(true);
                    this.frame.getContentPane().add(panel);
                    this.frame.pack();
                    //             if(started){  
                    this.frame.setVisible(true); 
    
                  }
    
    
                  public void  update() {
    
    
    
                     //toDo
    
                  }
    
                  public  void remove() {
                     applet.stop(); 
                       frame.dispose();
                  }
                };
    
  • @akenaton Thanks. Is this Java code? I simply did copy-paste into the Processing code editor, commented out the lines of

    <a href="/two/profile/Override">@Override</a>

    then tried to run it. Error on

    applet.(init);

    "the function 'init' does not exist"

  • @akenaton, add a space between @ & Override.
    That's for the same reason we need to type http:/ + /SomeSite.some. ;)

  • @GoToLoop== @Override, bad eclipse habitude...i note! - thanks

  • @regitmail: see the GoToLoop answer; its only typo with the forum: you suppress < href"/two/profile/ then what is after the second> you leave only " @Override" instead of that....This code runs, i tested.

  • @akenaton, I think it'd be easier if you simply re-edit the posted code rather than asking the OP to replace that weird href. *-:)

  • @GoToLoop:: right, i do that

  • @regitmail:: as asked goToLoop i have updated the code, so you have nothing to do.

  • @akenaton I did copy-paste of the updated code into Processing and tried running it (Java mode). Error on line 195. "The function "init()" does not exist; the same error that occurred with the original code.

    I'm running Processing 3.0b6 on Windows 8.1.

  • @regitmail== perhaps some cut/copy error :: i have to test, but this code works and init() is classical with PApplet. I tell you to morrow.

  • @akenaton, no copy-paste error. I even deleted the line and typed it in. In fact, in the Processing IDE, the functions are colored blue. For example, for applet.start();, start is colored blue. But on the lines with applet. init();, it remains black. Therefore, the init() function isn't found.

  • @regitmail: no; applet.init() exists && works, blue or black! - problem could be that you are using processing3, i have written && tested with processing 2.X; i ll try with 3 in order to verify.

  • @regitmail:: i am not alone to think that Applet.init() method exists and that you must call it when you put PApplet instance in a Frame:::: see here what is answering KevinWorkman at somebody who tries WITHOUT init()=====

    "Default Re: PApplet not displaying (processing.core.PApplet) You have to add your PApplet to a window such as a JFrame. You called your class GraphFrame, but it's not actually a Frame, it's a PApplet. PApplets need to be inside windows. Something like this:

    Java Code:

        JFrame frame = new JFrame("I'm a JFrame");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        PApplet papplet = new Papplet();
        frame.add(papplet);
        papplet.init();
        frame.setVisible(true);
    

    java-forums.org/awt-swing/84857-papplet-not-displaying-processing-core-papplet.html

    ...And it works with P52.X --YET you are absolutely right, i tried exactly the same code but with 3.X && it fires what you said...I don't know why, i have to look to the changes; if you can try with 2.X...

  • @regitmail::: OK, it was what i thought && so this is a big problem! "downside"::

    "As of Processing 3.0, we have removed Applet as the base class for PApplet. This means that we can remove lots of legacy code, however one downside is that it's no longer possible (without extra code) to embed a PApplet into another Java application"

    What "extra code", they don't tell....

  • @akenaton. Thanks for tracking down the problem. But even with Applet removed, can't I just copy the Applet code to my sketch, then subclass PApplet to that?

  • Answer ✓

    @regitmail:: i think no.I think that it could be easier to get p5 2.3 and work with it!!! - I have posted a question about this problem and it seems that it is not so easy to write this famous "extra code". I have tried the solution written by GoToLoop using some mysterious method (black!, not blue!, like init()) called runSketch() but till now i am far away to be able to do with it all that i can do with JFrame; perhaps GoToLoop will answer the last questions i posted: wait & see.

  • @regitmail=== bad news see here::forum.processing.org/two/discussion/comment/52163#Comment_52163 -that means that i can do nothing for your problem with P.3X

  • In Java the ONLY types of control you can add to a JFrame are those that have a visual representation. In PS2 PApplet inherited from the class java.awt.Applet which is a visual control so could be added to the sketch's frame.

    In PS3 PApplet no longer inherits from Applet, in fact it doesn't extend any class and has no visual representation. It means that line 4 of your code above is in valid for PS3

  • edited October 2015

    @quark:: yes, i do know (see my posts) but how to do if i want to create AND control some new window (look and feel, user interaction, location, background) AND put in it an instance of PApplet extending the class??? - See the other discussion with GoToLoop who uses runSketch() for that : it seems to me that you can control quite nothing in this way...till now!

  • The code in this discussion will enable you to create separate independent windows each with their own mouse and draw handlers. It is fairly simple to extend it to include key handling.

    I created the code when testing alternative methods to create multiple windows because I am modifying G4P to make it PS3 compatible.

  • @quark:: yes, of course:: the whole stuff of G4P is on the table... so, i ll see, of course (btw: is Papplet no longer an Object???) :(

  • @quark:: seriously tomorrow.....now if i dont leave i ll divorce && java cannot do nothing about that!(1.8)

  • Yes, PApplet does extend Object because in Java all classes descend from the Object class :)

  • @quark:: for fun! " in fact it doesn't extend any class" - you said...

  • So you're saying that now PApplet descends directly from Object (In processing 3)?

  • So you're saying that now PApplet descends directly from Object (In processing 3)?

    Yes

    Line 105 of the PApplet source code is

    public class PApplet implements PConstants {

  • @regitmail:: using the infos/change in P3X + hints from GoToLoop && quark, i have tried to rewrite quickly the code using Psurface instead of JFrame and the "occult" method runSketch(): i tested && it works with P3. As soon as i have added some details i ll post it there.

  • I have a quite similiar problem with P3: some functions of PApplet don´t work e.g. frame.add() init() resize()

    Is there any possibility to fix this or could anybody give a hint how to do so?

  • I want to put P3 into a java class to communicate with another class: MaxObject from cyclings74 Max(msp).

Sign In or Register to comment.