Closing second window by button event
in
Contributed Library Questions
•
7 months ago
Hi everybody!
I'm trying to realize a little sketch in which second window is opened when space bar is hit. This is my sketch:
- import controlP5.*;
- import processing.serial.*;
- PFrame f;
- secondApplet s;
- ControlP5 cp5;
- Serial serial;
- Serial myPort;
- ListBox l;
- void setup() {
- size(320, 240);
- }
- void draw() {
- background(0, 255, 0);
- fill(255);
- }
- public class PFrame extends Frame {
- public PFrame() {
- setBounds(600, 300, 400, 300);
- s = new secondApplet();
- add(s);
- s.init();
- show();
- }
- }
- public class secondApplet extends PApplet {
- public void setup() {
- size(400, 300);
- cp5 = new ControlP5(this);
- cp5.addBang("Close")
- .setPosition(140, 190)
- .setSize(50, 20)
- .getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
- ;
- }
- public void draw() {
- background(255, 0, 0);
- }
- }
- void keyPressed() {
- if (key==' ') {
- key=0;
- PFrame f = new PFrame();
- s.background(0, 0, 255);
- s.fill(100);
- s.rect(10, 20, frameCount, 0, 10);
- s.redraw();
- }
- }
- public void Close() {
- s.stop();
- }
As You can observe second window has button called "Close", which should close the window (letting the main window opened), but it does not happen. I would like to know if it's even possible to close the second window by the "x" button in titlebar without close the first one. Can you help me??
1