We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Multiple PApplet windows
Page Index Toggle Pages: 1
Multiple PApplet windows (Read 730 times)
Multiple PApplet windows
May 17th, 2009, 12:14pm
 
When searching the forum I found the following code (posted by smallfry back in 2007)

It creates a second PApplet window (inside a Java Frame).

When I close either window it closes both, what I want to be able to do is close the second window leaving the initial window open.

Removing the System.exit(0) simply prevents the second window from closing!

Any ideas welcome?

Code:

private static secondCanvas sCanvas;
private static secondApplet sApplet;

import java.awt.*;
import java.awt.event.*;
import processing.core.*;

int xPos = 0;
int yPos = 0;

void setup() {
 size(400, 400);
 smooth();
 background(0);
 noStroke();

 sApplet = new secondApplet();
 sCanvas = new secondCanvas("follower", sApplet, screen.width/2, screen.height/2);
}

void draw() {
 background(0);
 fill(200, 100, 0);
 rect(xPos++,0, 100, 100);
 if(xPos >= width) xPos = 0;
}


public class secondApplet extends PApplet {

 public void setup() {
   size(400, 400);
   background(255, 0, 0);
   frameRate(10);
 }

 public void draw() {
   background(0);
   fill(200, 100, 0);
   rect(0, yPos++, 100, 100);
   if(yPos >= height) yPos = 0;
 }
}


public class secondCanvas extends Frame {
 public secondCanvas(String name, PApplet embed, int x, int y) {
   super(name);

   // add the PApplet to the Frame
   setLayout(new BorderLayout());
   add(embed, BorderLayout.CENTER);

   // ensures that the animation thread is started and
   // that other internal variables are properly set.
   embed.init();

   // add an exit on close listener
   addWindowListener(new WindowAdapter() {
     public void windowClosing(WindowEvent evt) {
       // exit the application
       System.exit(0);
     }
   });

   setSize(400, 400);
   setLocation(x, y);
   setVisible(true);

 }
}
Re: Multiple PApplet windows
Reply #1 - May 17th, 2009, 1:26pm
 
If I am not mistaken, you should call dispose() instead.
Re: Multiple PApplet windows
Reply #2 - May 17th, 2009, 2:17pm
 
That worked a treat.

Thanks  PhiLho Cheesy
Page Index Toggle Pages: 1