java - Creating a second applet(window) in processing -


hello guys trying code can create second applet in processing passing on sensible area.

the code works fine except 1 thing.

when passes on sensible area creates in loop same frame.

here code.

import javax.swing.jframe;  pframe f; secondapplet s;  void setup() {   size(600, 340);  }  void draw() {   background(255, 0, 0);   fill(255); }       void mousepressed(){    pframe f = new pframe(); }   public class secondapplet extends papplet {    public void setup() {     size(600, 900);      noloop();   }   public void draw() {     fill(0);     ellipse(400, 60, 20, 20);   } }  public class pframe extends jframe {   public pframe() {      setbounds(0, 0, 600, 340);     s = new secondapplet();     add(s);     s.init();     println("birh");     show();   } } 

this code creates second applet clicking in region of frame, if keep clicking create more frames of same applet.

what want once click creates 1 frame , no more.

can me please? ;)

the code posted won't compile, have no top-level encapsulating class declared, i'm curious why works.

regarding issue, have field pframe f declared @ top, in mousepressed() declare one. variable f different first variable. solve problem, want code like:

void mousepressed() {   if (f == null) {     f = new pframe();   } } 

this allow create new frame, once. recommend choose more descriptive variable names, though. also, should secondapplet, not secondapplet.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -