Applet windows and saveFrame()

edited January 2014 in How To...

Hi!

I'm using multiple applet windows using the solution by quark in this post (http://forum.processing.org/two/discussion/1525/multiple-processing-applet-windows#Item_10). I'm trying to use saveFrame() to save the frames of one of the "extra" windows (not the main windows), but it's not working for the moment. I don't know how to do it :( Any idea/suggestion?

Thanks! R.

Answers

  • Wild speculation about the G4P library implementation: try papplet.saveFrame(). It would be logical, at least.

  • Answer ✓

    I'm trying to use saveFrame() to save the frames of one of the "extra" windows (not the main windows), but it's not working for the moment.

    I think you will find the saved images in the root user folder. When Processing launches a sketch it sets the sketch folder path and uses this with saveFrame(). The ControlFrame is created inside the sketch so the sketch folder path is not set for it.

    Since saveFrame() can only be used from the draw() or mouse/key event handling methods I have modified the example from the earlier post to show how to save the frame to the sketch folder.

    import java.awt.Frame;
    import java.awt.Dimension;
    import java.awt.BorderLayout;
    
    ControlFrame cf;
    
    public void setup() {
      size(200, 200 );
      cf = new ControlFrame(this, "Control Window2", 300, 300);
    }
    
    public void draw() {
      background(255, 240, 240);
      fill(255,0,0);
      text("Main window", width/2, height/2);
    }
    
    public void mouseClicked() {
      println("Window 2");
      saveFrame("window_main.png");
    }
    
    public class ControlFrame extends Frame {
      private ControlApplet papplet;
    
      public ControlFrame(PApplet sketch, String title, int w, int h) {
        papplet = new ControlApplet();
        papplet.savePath = sketch.sketchPath("");
        papplet.frame = this;
        // So we can resize the frame to get the sketch canvas size reqd.
        setResizable(true);
        setTitle(title);
        setLocation(900, 100);
        papplet.appWidth = w;
        papplet.appHeight = h;
    
        // Set the papplet size preferences
        papplet.resize(papplet.appWidth, papplet.appHeight);
        papplet.setPreferredSize(new Dimension(papplet.appWidth, papplet.appHeight));
        papplet.setMinimumSize(new Dimension(papplet.appWidth, papplet.appHeight));
        add(papplet);
        papplet.init();
        pack();
        setVisible(true);
      }
    }
    
    public class ControlApplet extends PApplet {
    
      public int appWidth, appHeight;
      public String savePath;
    
      public void setup() {
        size(appWidth, appHeight);
      }
    
      public void draw() {
        background(200, 200, 255);
        fill(0);
        noStroke();
        ellipse(width/2, height/2, 30, 30);
        stroke(255, 255, 0);
        strokeWeight(3);
        ellipse(150, 150, 30, 30); // ellipses should coincide on all platforms
        fill(0, 0, 128);
        text("Control window", width/2, height/2+70);
      }
    
      public void mouseClicked() {
        println("Window 2");
        saveFrame(savePath + "window_control.png");
      }
    
    }
    
  • "I think you will find the saved images in the root user folder."

    Yes quark, that is! Thank you very much!

Sign In or Register to comment.