From 71325def84f81abcff66ba8fb666f10a8fdc5eb6 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Tue, 21 Jan 2014 12:12:59 -0500 Subject: [PATCH] added EmbedFrameTest example in Demos/Test --- .../Tests/EmbedFrameTest/EmbedFrameTest.pde | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 java/examples/Demos/Tests/EmbedFrameTest/EmbedFrameTest.pde diff --git a/java/examples/Demos/Tests/EmbedFrameTest/EmbedFrameTest.pde b/java/examples/Demos/Tests/EmbedFrameTest/EmbedFrameTest.pde new file mode 100644 index 000000000..9a29eb58b --- /dev/null +++ b/java/examples/Demos/Tests/EmbedFrameTest/EmbedFrameTest.pde @@ -0,0 +1,88 @@ +// Based on code by GeneKao (https://github.com/GeneKao) + +import peasy.*; + +import javax.swing.JFrame; +import java.awt.BorderLayout; +import java.awt.Insets; +EmbeddedSketch eSketch; +ChildApplet child = new ChildApplet(); +boolean mousePressedOnParent = false; +PeasyCam cam, cam2; + +void setup() { + size(320, 240, P3D); + cam = new PeasyCam(this, 300); + eSketch = new EmbeddedSketch(child); + smooth(); +} + +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 +class EmbeddedSketch extends JFrame { + PApplet sketch; + EmbeddedSketch(PApplet p) { + int w = 400; + int h = 400; + sketch = p; + setVisible(true); + + setLayout(new BorderLayout()); + add(p, BorderLayout.CENTER); + p.init(); + + Insets insets = getInsets(); + setSize(insets.left + w, insets.top + h); + p.setBounds(insets.left, insets.top, w, h); + + setLocation(500, 200); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } +} + +class ChildApplet extends PApplet { + void setup() { + size(400, 400, P3D); + smooth(); + cam2 = new PeasyCam(this, 300); + cam2.reset(); + } + + 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); + } + } +} +