<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with setdefaultcloseoperation() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=setdefaultcloseoperation%28%29</link>
      <pubDate>Sun, 08 Aug 2021 21:25:03 +0000</pubDate>
         <description>Tagged with setdefaultcloseoperation() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedsetdefaultcloseoperation%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>How to create an object from processing class in eclipse ?</title>
      <link>https://forum.processing.org/two/discussion/25755/how-to-create-an-object-from-processing-class-in-eclipse</link>
      <pubDate>Fri, 29 Dec 2017 21:37:23 +0000</pubDate>
      <dc:creator>melisaztrk</dc:creator>
      <guid isPermaLink="false">25755@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I want to use swing with processing in eclipse. But when i generate object from my processing class i don't know what am i supposed to send to constructor method ? Image1 is my processing class and i want to generate an object by using it.</p>

<p>import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JComboBox;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;</p>

<p>public class main {</p>

<pre><code>private JFrame frame;
private JComboBox comboBox ;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    //PApplet.main("ProjectUsingProcessing");
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                main window = new main();
                window.frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the application.
 */
public main() {
    initialize();
}

/**
 * Initialize the contents of the frame.
 */
private void initialize() {
    frame = new JFrame();
    frame.setBounds(100, 100, 450, 300);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(null);

    JButton btnNewButton = new JButton("New button");
    btnNewButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String selected = comboBox.getSelectedItem().toString();

            if(selected=="Image1")
            {
                Image1 o1 = new Image1();
                o1.imageDraw();
            }
        }
    });
    btnNewButton.setBounds(29, 30, 89, 23);
    frame.getContentPane().add(btnNewButton);

    comboBox = new JComboBox();
    comboBox.setBounds(29, 104, 142, 23);
    comboBox.addItem("Image1");
    frame.getContentPane().add(comboBox);
}
</code></pre>

<p>}</p>
]]></description>
   </item>
   <item>
      <title>How to stop JFrame from closing after Processing sketch is closed</title>
      <link>https://forum.processing.org/two/discussion/25202/how-to-stop-jframe-from-closing-after-processing-sketch-is-closed</link>
      <pubDate>Sun, 26 Nov 2017 05:58:24 +0000</pubDate>
      <dc:creator>azaad</dc:creator>
      <guid isPermaLink="false">25202@/two/discussions</guid>
      <description><![CDATA[<p>So, I'm using Processing in a swing app and I'm wondering if there is a way to stop a JFrame from closing after the Processing sketch is stopped. This code will demonstrate my problem:</p>

<p><em>JFrameTest.pde</em></p>

<pre><code>Frame frame;
void setup(){
  frame = new Frame();
  size(300, 300);
}

void draw(){

}
</code></pre>

<p><em>Frame.pde</em></p>

<pre><code>import javax.swing.*;

class Frame extends JFrame {
  public Frame(){
    super("Panel");
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setSize(250, 250);
    this.setResizable(false);

    this.setVisible( true );
  }
}
</code></pre>

<p>I understand that in this case, Frame is a nested class of JFrameTest in Java. In my app, this isn't the case. I use the PApplet.main method to start Processing sketches but I'm curious if there is a solution from with the PDE!</p>
]]></description>
   </item>
   <item>
      <title>how can I run a processing sketch in a JPanel in Java.</title>
      <link>https://forum.processing.org/two/discussion/21741/how-can-i-run-a-processing-sketch-in-a-jpanel-in-java</link>
      <pubDate>Sat, 01 Apr 2017 05:29:36 +0000</pubDate>
      <dc:creator>mezbah</dc:creator>
      <guid isPermaLink="false">21741@/two/discussions</guid>
      <description><![CDATA[<p>I have a JPanel where I want to run a processing sketch which performs spectrum analysis.
I have tried psurface but it is giving me errors. Any Idea how to do it?
Hope I will get answers this time.
Thanks in advance</p>
]]></description>
   </item>
   <item>
      <title>Intercept window closure in P2D renderer (Processing 3)</title>
      <link>https://forum.processing.org/two/discussion/17310/intercept-window-closure-in-p2d-renderer-processing-3</link>
      <pubDate>Sun, 26 Jun 2016 15:14:20 +0000</pubDate>
      <dc:creator>kchoi</dc:creator>
      <guid isPermaLink="false">17310@/two/discussions</guid>
      <description><![CDATA[<p>Hello, all. What I want to do is to display a popup message that blocks the window from closing for the P2D renderer. I could have <code>exit()</code>make a blocking call, but then the main window doesn't refresh. So what I'd like to do is stop <code>exit()</code> from being called at all until the popup is dismissed. I can prevent the sketch from closing for the ESC key by intercepting it in <code>keyPressed()</code>, but I don't know how to make it work when I try to close the window directly via ALT+F4 or the window X button. For the default renderer I could just add an AWT window listener to <code>surface</code>, but P2D uses <code>GLWindow</code> as the underlying implementation, and I haven't figured out how to intercept OpenGL window events. So, my question: is what I want possible with P2D, and if so how do I do it?</p>
]]></description>
   </item>
   <item>
      <title>embedding PApplet in Java JFrame</title>
      <link>https://forum.processing.org/two/discussion/12774/embedding-papplet-in-java-jframe</link>
      <pubDate>Thu, 01 Oct 2015 14:35:54 +0000</pubDate>
      <dc:creator>akenaton</dc:creator>
      <guid isPermaLink="false">12774@/two/discussions</guid>
      <description><![CDATA[<p>till processing 3 i have often made that successfully. Yesterday, answering to some question that you can see here 
<a rel="nofollow" href="http://forum.processing.org/two/discussion/12624/can-i-launch-an-instance-of-processing-inside-of-a-control-on-a-sketch#latest">forum.processing.org/two/discussion/12624/can-i-launch-an-instance-of-processing-inside-of-a-control-on-a-sketch#latest</a>
i posted the code you can see at the same url. This code works, i have used it many times and tested the snippet i put. Yet theOP said me "this code does not work, it fires that the applet.init() method does not exist" and he added that he was using processing 3. So, i went to the docs / changes &amp;&amp; found that:</p>

<p>"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"</p>

<p>ok. But i would be very happy to understand by an example what kind of "extra code" i could use...
thanks in advance</p>
]]></description>
   </item>
   <item>
      <title>Processing 3 with P3D embedded in JPanel</title>
      <link>https://forum.processing.org/two/discussion/17351/processing-3-with-p3d-embedded-in-jpanel</link>
      <pubDate>Wed, 29 Jun 2016 03:52:25 +0000</pubDate>
      <dc:creator>SChichin</dc:creator>
      <guid isPermaLink="false">17351@/two/discussions</guid>
      <description><![CDATA[<p>In my current project, I need to embed a Processing 3 canvas in my Java Swing application. I could find some good examples for P2D renderer, which worked perfectly fine; however, my application is using P3D renderer for displaying 3D models.</p>

<p>After a thorough search on the Internet and reading the source codes, I could get a solution, which does not work properly.</p>

<p>Here is a baby example of what I have so far followed by the screenshots of my issue (the example uses JFrame for simplicity and conciseness).</p>

<pre><code>public class Visualiser3D extends PApplet {

    private PeasyCam camera;

    @ Override
    public void settings() {
        size(1000, 800, P3D);
    }

    @ Override
    public void setup() {
        camera = new PeasyCam(this, 0, 0, 0, 1500);
    }

    @ Override
    public void draw() {
        camera();        // force default coordsys
        camera.feed();   // manually set peasycam
        background(30);
        sphere(200);    // draw a sphere
    }

    public static void main (String[] args) {
        // prepare JFrame
        JFrame frame = new JFrame("Processing in JFrame");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLayout(new BorderLayout());

        // run Processing
        Visualiser3D mp3d = new Visualiser3D();
        PApplet.runSketch(new String[]{"MyPapplet 3D"}, mp3d);
        PSurfaceJOGL pSurfaceJOGL = (PSurfaceJOGL) mp3d.getSurface();
        pSurfaceJOGL.initOffscreen(mp3d);
        // add canvas to JFrame (used as a Component)
        NewtCanvasAWT canvas = (NewtCanvasAWT) pSurfaceJOGL.getComponent();
        frame.add(canvas, BorderLayout.CENTER);        
        pSurfaceJOGL.startThread();

        // display
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
} 
</code></pre>

<p>Here are the screenshots of what I get. The actual processing window keeps running, and if I close it programmatically, the entire application gets closed. I would like to have the Processing canvas embedded inside of my Java Swing application without any other open windows.</p>

<p><img src="http://i.stack.imgur.com/RuPxM.png" alt="JFrame with inserted Processing Canvas" />
<img src="http://i.stack.imgur.com/bS8tD.png" alt="Processing Window running" /></p>

<p>I hope that you will be able to help me do it properly. Thank you very much.</p>
]]></description>
   </item>
   <item>
      <title>Using PApplet.runSketch to create multiple windows in a PS3 sketch.</title>
      <link>https://forum.processing.org/two/discussion/12319/using-papplet-runsketch-to-create-multiple-windows-in-a-ps3-sketch</link>
      <pubDate>Mon, 31 Aug 2015 15:52:26 +0000</pubDate>
      <dc:creator>quark</dc:creator>
      <guid isPermaLink="false">12319@/two/discussions</guid>
      <description><![CDATA[<p>I have been experimenting with PApplet.runSketch to create multiple windows with limited success.</p>

<p>My main question is :- Is it appropriate for a library, such as G4P, to use this method to create multiple windows in a PS3 sketch? If not what is?</p>

<p><del>In the following code I have been experimenting with the args argument to this method. Based on my research the code below should open the secondary window in the top left corner but it uses the default screen centre instead. Any thoughts?</del><br />
<strong>EDIT this problem was solved thanks to GoToLoop's PS3 code below</strong></p>

<p><strong>EDIT this code has been corrected for PS3</strong></p>

<pre><code>// Main sketch (first) tab

void settings(){
  size(600, 200);  
}

void setup() {
  String[] args = {"--location=0,0", "Foo"};
  Foo sa = new Foo(320, 240);
  PApplet.runSketch(args, sa);
}

void draw() {
  background(0);
  ellipse(50, 50, 10, 10);
}     
</code></pre>

<hr />

<pre><code>// Foo.java tab

import processing.core.*;

public class Foo extends PApplet {

  private final int w, h;

  public Foo() {
    w = 200;
    h = 200;
  }

  public Foo(int w, int h) {
    this.w = w;
    this.h = h;
  }

  public void settings() {
    size(w, h);
  }

  public void draw() {
    background(255);
    fill(0);
    ellipse(100, 50, 10, 10);
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Processing 3: Disable (or Remove) Window Close Button</title>
      <link>https://forum.processing.org/two/discussion/14437/processing-3-disable-or-remove-window-close-button</link>
      <pubDate>Wed, 13 Jan 2016 19:11:00 +0000</pubDate>
      <dc:creator>batroost</dc:creator>
      <guid isPermaLink="false">14437@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>Apologies if I've missed the answer to this one, but I have spent a long time looking.</p>

<p>I'm using Processing3 to display a game for use by school children in a Visitor's Centre. The game is mouse-driven but I can't risk displaying a close button on the frame as someone will use it... Is there any way of producing an undecorated frame in processing 3. The only suggestions I've seen involve the 'frame.' commands which don't appear to work in P3?</p>

<p>Leaving the sketch using the escape key is OK as the keyboard will be locked-away.</p>

<p>If it can be avoided, I'd rather not have this window full-screen, though that is still an outside option.</p>

<p>Thanks,</p>

<p>Batroost</p>
]]></description>
   </item>
   <item>
      <title>Can I launch an instance of Processing inside of a control on a sketch?</title>
      <link>https://forum.processing.org/two/discussion/12624/can-i-launch-an-instance-of-processing-inside-of-a-control-on-a-sketch</link>
      <pubDate>Mon, 21 Sep 2015 19:05:45 +0000</pubDate>
      <dc:creator>regitmail</dc:creator>
      <guid isPermaLink="false">12624@/two/discussions</guid>
      <description><![CDATA[<p>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?</p>
]]></description>
   </item>
   <item>
      <title>PS3 - Secondary window problem with WindowListener</title>
      <link>https://forum.processing.org/two/discussion/12382/ps3-secondary-window-problem-with-windowlistener</link>
      <pubDate>Thu, 03 Sep 2015 17:33:03 +0000</pubDate>
      <dc:creator>quark</dc:creator>
      <guid isPermaLink="false">12382@/two/discussions</guid>
      <description><![CDATA[<p>Download this code as an <strong><a rel="nofollow" href="http://www.lagers.org.uk/zzz/G4PWinTest_A-150903a.zip">archived sketch</a></strong></p>

<p>I am working on updating G4P for PS3 and I have managed to create multiple windows with either JAVA2D, P2D or P3D renderers. The problem is that the secondary Window created by Processing, when closed exits the application. In the existing version of G4P the user can specify what to do when the user clicks on the red cross. Either keep the window open, close the window or exit the application and I am trying to do the same thing for PS3.</p>

<p>So the code below is a cut down version to demonstrate the problem. In line 16 the user can specify which of these 3 actions is used. The CLOSE_WINDOW and EXIT_APP work as expected but the KEEP_OPEN option still allows the window to close. :(</p>

<p>In the G3WindowA class the <code>intAWTlisteners()</code> method removes all existing WindowListeners and then adds one of its own (inner class WindowListenerAWT).</p>

<p>This is exactly the same approach I used in the last version of G4P which worked fine in 2.2.1</p>

<p>Any help would be appreciated.</p>

<p>Main sketch tab</p>

<pre><code>// These are used by the secondary window to test mouse event
int x, y;
float a;

public void settings() {
  size(100, 100);
}

public void setup() {
  // Creates a window with a JAVA2D renderer 
  // (do not change renderers in this test)
  G3WindowA g3w = G3WindowA.getWindow("My window", 20, 40, 480, 320, JAVA2D);
  // KEEP_OPEN - ignore attempt to close window (default action) &lt;br&gt;
  // CLOSE_WINDOW - close this window, if it is the main window it causes the app to exit &lt;br&gt;
  // EXIT_APP - exit the app, this will cause all windows to close. &lt;br&gt;
  g3w.setActionOnClose(G3WindowA.KEEP_OPEN);
  g3w.addDrawHandler(this, "g3wDraw");
}

public void draw() {
  background(0);
  ellipse(mouseX, mouseY, 20, 20);
}     

// Draw and mouse event handlers for secondary window
public void g3wDraw(PApplet app, GWinData data) {
  app.background(255);
  app.fill(0);
  app.ellipse(app.mouseX, app.mouseY, 10, 10);
}
</code></pre>

<p><strong>G3WindowA.java</strong> tab</p>

<pre><code>import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.lang.reflect.Method;

import processing.core.PApplet;

public final class G3WindowA extends PApplet {

  /**
   * Factory method to create and start a new window
   * 
   * <a href="/two/profile/param">@param</a> title text to appear in frame title bar
   * <a href="/two/profile/param">@param</a> px horizontal position of top-left corner
   * <a href="/two/profile/param">@param</a> py vertical position of top-left corner
   * <a href="/two/profile/param">@param</a> w width of drawing surface
   * <a href="/two/profile/param">@param</a> h height of surface
   * <a href="/two/profile/param">@param</a> r renderer e.g. JAVA2D, P3D etc.
   * <a href="/two/profile/return">@return</a> the window created (in case the user wants its.
   */
  public static G3WindowA getWindow(String title, int px, int py, int w, int h, String r) {
    G3WindowA g3w = new G3WindowA(title, w, h, r);
    String loc = "--location=" + px + "," + py;
    String className = g3w.getClass().getName();
    String[] args = { loc, className};
    PApplet.runSketch(args, g3w);
    return g3w;
  }

  /** The object to handle the draw event */
  private Object drawHandlerObject = null;
  /** The method in drawHandlerObject to execute */
  private Method drawHandlerMethod = null;
  /** the name of the method to handle the event */
  private String drawHandlerMethodName;

  //*********************************************************
  // Copied from GConstants
  public static final int EXIT_APP       = 0x00000f01;
  public static final int CLOSE_WINDOW     = 0x00000f02;
  public static final int KEEP_OPEN       = 0x00000f03;
  //**********************************************************

  static final int _INVALID = 0;
  static final int _AWT = 1;      // JAVA2D
  static final int _NEWT = 2;    // P2D or P3D

  private int renderer_type = _INVALID;

  private int actionOnClose = KEEP_OPEN;

  public GWinData data;

  private final int w, h;
  private final String r, title;

  private WindowListener awtAdapter = new WindowListenerAWT();

  private G3WindowA(String title, int w, int h, String renderer) {
    this.title = title;
    this.w = w;
    this.h = h;
    this.r = renderer;
    renderer_type = _INVALID;
    if (renderer.equals(JAVA2D))
      renderer_type = _AWT;
    else if (renderer.equals(P2D) || renderer.equals(P3D))
      renderer_type = _NEWT;
    System.out.println(renderer_type);
    registerMethod("draw", this);
  }

  public void settings() {
    size(w, h, r);
  }

  public void setup() {
    surface.setTitle(title); // does not like this in settings  
    Object obj = surface.getNative();
    System.out.println(obj.getClass().getName());
    switch(renderer_type) {
    case _AWT:
      processing.awt.PSurfaceAWT.SmoothCanvas awtCanvas = (processing.awt.PSurfaceAWT.SmoothCanvas) obj;
      //System.out.println(awtCanvas.getFrame().getClass().getName());
      frame = awtCanvas.getFrame();
      intAWTlisteners();
      break;
    }
  }

  // Remove all WindowListeners and add own own
  private void intAWTlisteners() {
    frame = ((processing.awt.PSurfaceAWT.SmoothCanvas) surface.getNative()).getFrame();
    for (WindowListener l : frame.getWindowListeners())
      frame.removeWindowListener(l);
    frame.addWindowListener(awtAdapter);
  }

  public void draw() {
    pushMatrix();
    if (drawHandlerObject != null) {
      try {
        drawHandlerMethod.invoke(drawHandlerObject, new Object[] { this, data });
      } 
      catch (Exception e) {
        //  ERROR
      }
    }
    popMatrix();
  }

  /**
   * Attempt to add the 'draw' handler method. 
   * The default event handler is a method that returns void and has two
   * parameters PApplet and GWinData
   * 
   * <a href="/two/profile/param">@param</a> obj the object to handle the event
   * <a href="/two/profile/param">@param</a> methodName the method to execute in the object handler class
   */
  public void addDrawHandler(Object obj, String methodName) {
    try {
      drawHandlerMethod = obj.getClass().getMethod(methodName, new Class&lt;?&gt;[] {PApplet.class, GWinData.class } );
      drawHandlerObject = obj;
      drawHandlerMethodName = methodName;
    } 
    catch (Exception e) {
      drawHandlerObject = null;
      //GMessenger.message(NONEXISTANT, new Object[] {this, methodName, new Class&lt;?&gt;[] { PApplet.class, GWinData.class } } );
    }
  }

  /**
   * This sets what happens when the users attempts to close the window. &lt;br&gt;
   * There are 3 possible actions depending on the value passed. &lt;br&gt;
   * KEEP_OPEN - ignore attempt to close window (default action) &lt;br&gt;
   * CLOSE_WINDOW - close this window, if it is the main window it causes the app to exit &lt;br&gt;
   * EXIT_APP - exit the app, this will cause all windows to close. &lt;br&gt;
   * <a href="/two/profile/param">@param</a> action the required close action
   */
  public void setActionOnClose(int action) {
    actionOnClose = action;
  }

  /**
   * Window adapter class that remembers the window it belongs to so
   * it can be used to mark it for closure if required.
   * 
   * <a href="/two/profile/author">@author</a> Peter Lager
   */
  public class WindowListenerAWT implements WindowListener {

    <a href="/two/profile/Override">@Override</a>
      public void windowClosing(WindowEvent evt) {
      System.out.println("CLOSING AWT");
      switch(actionOnClose) {
        case EXIT_APP:
          System.out.println("EXIT");
        System.exit(0);
        break;
      case CLOSE_WINDOW:
        System.out.println("CLOSE");
        noLoop();
        unregisterMethod("draw", this);
        dispose();
        break;
      default:
        System.out.println("KEEP OPEN");
      }
    }

    <a href="/two/profile/Override">@Override</a>
      public void windowOpened(WindowEvent e) {
    }

    <a href="/two/profile/Override">@Override</a>
      public void windowClosed(WindowEvent e) {
      System.out.println("AWT WINDOW CLOSED");
    }

    <a href="/two/profile/Override">@Override</a>
      public void windowIconified(WindowEvent e) {
    }

    <a href="/two/profile/Override">@Override</a>
      public void windowDeiconified(WindowEvent e) {
    }

    <a href="/two/profile/Override">@Override</a>
      public void windowActivated(WindowEvent e) {
    }

    <a href="/two/profile/Override">@Override</a>
      public void windowDeactivated(WindowEvent e) {
    }
  }
}
</code></pre>

<p><strong>GWinData.java</strong> tab</p>

<pre><code>public class GWinData {
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Prevent closing all frames</title>
      <link>https://forum.processing.org/two/discussion/11562/prevent-closing-all-frames</link>
      <pubDate>Sat, 04 Jul 2015 14:45:13 +0000</pubDate>
      <dc:creator>clankill3r</dc:creator>
      <guid isPermaLink="false">11562@/two/discussions</guid>
      <description><![CDATA[<p>I want to make a sketch that can open other sketches.
So far it goes good but I can't change the behaviour of the sketches that are opened on runtime.</p>

<p>Why has the setDefaultCloseOperation no effect?</p>

<p>(Also, it should be DISPOSE_ON_CLOSE but I'm using DO_NOTHING_ON_CLOSE for testing).</p>

<pre><code>public class AllSketches extends PApplet {

    public static void main(String[] args) {
        PApplet.main("forMyself.AllSketches", args);
    }

    P5_BackFaceCulling backFaceCulling;

    public void setup() {


        // works
        ((JFrame)getFrame()).setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    }

    public void draw() {

    }

    public void keyPressed() {
        if (key == '1') {
            println("test");

            Frame f = backFaceCulling.getFrame();

            if (f instanceof JFrame) {
                // why has this no effect?
                ((JFrame)f).setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
                println("changed setDefaultCloseOperation");
            }

        }
    }

}
</code></pre>
]]></description>
   </item>
   </channel>
</rss>