FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

added EmbedFrameTest example in Demos/Test · ranlevinstein/processing@dc29d4e · GitHub

Repository navigation

Commit dc29d4e

Browse files
committed
added EmbedFrameTest example in Demos/Test
1 parent f16bac1 commit dc29d4e

1 file changed

Lines changed: 88 additions & 0 deletions

File tree

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Based on code by GeneKao (https://github.com/GeneKao)
2+
3+
import peasy.*;
4+
5+
import javax.swing.JFrame;
6+
import java.awt.BorderLayout;
7+
import java.awt.Insets;
8+
EmbeddedSketch eSketch;
9+
ChildApplet child = new ChildApplet();
10+
boolean mousePressedOnParent = false;
11+
PeasyCam cam, cam2;
12+
13+
void setup() {
14+
size(320, 240, P3D);
15+
cam = new PeasyCam(this, 300);
16+
eSketch = new EmbeddedSketch(child);
17+
smooth();
18+
}
19+
20+
void draw() {
21+
background(250);
22+
if (mousePressed) {
23+
fill(0);
24+
text("Mouse pressed on parent.", 10, 10);
25+
fill(0, 240, 0);
26+
ellipse(mouseX, mouseY, 60, 60);
27+
mousePressedOnParent = true;
28+
} else {
29+
fill(20);
30+
ellipse(width/2, height/2, 60, 60);
31+
mousePressedOnParent = false;
32+
}
33+
box(100);
34+
if (eSketch.sketch.mousePressed) {
35+
text("Mouse pressed on child.", 10, 30);
36+
}
37+
}
38+
39+
//The JFrame which will contain the child applet
40+
class EmbeddedSketch extends JFrame {
41+
PApplet sketch;
42+
EmbeddedSketch(PApplet p) {
43+
int w = 400;
44+
int h = 400;
45+
sketch = p;
46+
setVisible(true);
47+
48+
setLayout(new BorderLayout());
49+
add(p, BorderLayout.CENTER);
50+
p.init();
51+
52+
Insets insets = getInsets();
53+
setSize(insets.left + w, insets.top + h);
54+
p.setBounds(insets.left, insets.top, w, h);
55+
56+
setLocation(500, 200);
57+
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
58+
}
59+
}
60+
61+
class ChildApplet extends PApplet {
62+
void setup() {
63+
size(400, 400, P3D);
64+
smooth();
65+
cam2 = new PeasyCam(this, 300);
66+
cam2.reset();
67+
}
68+
69+
void draw() {
70+
background(0);
71+
if (mousePressed) {
72+
fill(240, 0, 0);
73+
ellipse(mouseX, mouseY, 20, 20);
74+
fill(255);
75+
text("Mouse pressed on child.", 10, 30);
76+
} else {
77+
fill(255);
78+
ellipse(width/2, height/2, 20, 20);
79+
}
80+
81+
box(100, 200, 100);
82+
if (mousePressedOnParent) {
83+
fill(255);
84+
text("Mouse pressed on parent", 20, 20);
85+
}
86+
}
87+
}
88+

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL