Two applet worked in 1.5.1 version but not in 2.0.3 why?

edited October 2013 in Programming Questions

Hi, I was using Processing 1.5.1 version and did some of my projects. I use this method, suggest from Manindra29, to call JFrame because I wanted to use two applets for data transference. It works perfect in 1.5.1, both P3D and OPENGL.

Screen Shot 2013-10-30 at 11.38.36 AM

However, when I change it to 2.0.3 version recently, I found the child applet doesn't work on P3D(P2D works fine).........does anyone know how can I fix this? or any possible solutions will be worth trying. Big thanks :))))

By the way, my operating system is osx mountain lion.

Screen Shot 2013-10-30 at 11.40.25 AM

here is the code

import peasy.*; 

import javax.swing.JFrame;
EmbeddedSketch eSketch;
ChildApplet child = new ChildApplet();
boolean mousePressedOnParent = false;

PeasyCam cam, cam2;

public void setup() {
  size(320, 240, P3D);
  cam = new PeasyCam(this, 300);
  eSketch = new EmbeddedSketch(child);
  smooth();
}

public void draw() {
  background(250);


  if (mousePressed) {
    fill(0);
    text("Mouse pressed on parent.", 10, 10);
    fill(0, 240, 0);
    ellipse(mouseX, mouseY, 60, 60);
    mousePressedOnParent = true;
  }
  else {
    fill(20);
    ellipse(width/2, height/2, 60, 60);
    mousePressedOnParent = false;
  }

  box(100);

  if (eSketch.sketch.mousePressed)
    text("Mouse pressed on child.", 10, 30);
}


//The JFrame which will contain the child applet
public class EmbeddedSketch extends JFrame {
  PApplet sketch;
  public EmbeddedSketch(PApplet p) {
    setBounds(100, 100, 400, 400);
    add(p);
    p.init();
    sketch = p;
    setLocation(500, 200);
    //Program exits
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
  }
}

public class ChildApplet extends PApplet {
  public void setup() {
    size(400, 400, P3D);
    smooth();
    cam2 = new PeasyCam(this, 300);
    cam2.reset();
  }

  public void draw() {
    background(0);
    if (mousePressed) {
      fill(240, 0, 0);
      ellipse(mouseX, mouseY, 20, 20);
      fill(255);
      text("Mouse pressed on child.", 10, 30);
    }
    else {
      fill(255);
      ellipse(width/2, height/2, 20, 20);
    }   
    box(100, 200, 100); 

    if (mousePressedOnParent) {
      fill(255);
      text("Mouse pressed on parent", 20, 20);
    }
  }
}
Tagged:

Answers

Sign In or Register to comment.