# Implementing a Processing app inside another one

**URL:** <https://discourse.processing.org/t/implementing-a-processing-app-inside-another-one/44920>\
**Category:** Coding Questions\
**Created:** [August 10, 2024, 2:30pm UTC](https://discourse.processing.org/t/implementing-a-processing-app-inside-another-one/44920 "2024-08-10T14:30:32Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [August 18, 2024, 3:58pm UTC](https://discourse.processing.org/t/implementing-a-processing-app-inside-another-one/44920/22 "2024-08-18T15:58:02Z")

</div>

> [@svan](#):
>
> There’s quite a bit of animation of the slot machine when the handle is hit or a coin is dropped. Is that a problem to reproduce with a PGraphic?

For whatever it’s worth, here is a short demo of changing scenes, each with animated PGraphics. It also works with a P3D renderer. The Button class code goes under a separate tab or inline, whatever you prefer.

```auto
PGraphics circles;
PGraphics squares;

int _wndW = 600;
int _wndH = 650;

Button _btn1;
Button _btn2;

color BLUE = color(64, 124, 188);
color LTGRAY = color(185, 180, 180);
color YELLOW = color(245, 250, 13);
color GREEN = color(0, 255, 0);
color RED = color(255, 0, 0);
color BLACK = color(0, 0, 0);
color WHITE = color(255, 255, 255);

boolean showCircles = false;
boolean showSquares = false;

void setup() {
  size(_wndW, _wndH);
  circles = createGraphics(width, height);
  squares = createGraphics(width, height);
  _btn1 = new Button( 30, 10, 100, 24, "Circles", YELLOW, BLACK);
  _btn2 = new Button( 140, 10, 120, 24, "Squares", LTGRAY, BLACK);
}

void draw() {
  background(0);
  _btn1.display();
  _btn2.display();

  if (showCircles) {
    circles.beginDraw();
    circles.fill(random(255),random(255),random(255));
    circles.circle(random(width),random(height),15);
    circles.endDraw();
    image(circles, 0, 60);
  }
  if (showSquares) {
    squares.beginDraw();
    squares.fill(random(255),random(255),random(255));
    squares.rect(random(width), random(height), 15, 15);
    squares.endDraw();
    image(squares, 0, 60);
  }
}

void mousePressed() {
  if ((mouseX >= _btn1.x) && (mouseX <= _btn1.x + _btn1.w) && (mouseY >= _btn1.y) && (mouseY <= _btn1.y + _btn1.h)) {
    showCircles = true;
    showSquares = false;
  }
  if ((mouseX >= _btn2.x) && (mouseX <= _btn2.x + _btn2.w) && (mouseY >= _btn2.y) && (mouseY <= _btn2.y + _btn2.h)) {
    showSquares = true;
    showCircles = false;
  }
}

```

**Button class:**

```auto
class Button {
  float x, y, w, h;
  String title;
  color btnColor;
  color txtColor;

  // Constructor
  Button(int xpos, int ypos, float wt, float ht, String titleStr, color background, color foreground) {
    x = xpos;
    y = ypos;
    w = wt;
    h = ht;
    title = titleStr;
    btnColor = background;
    txtColor = foreground;
  }

  void display() {
    fill(btnColor); // button color
    noStroke();
    rect( x, y, w, h, 15); // rounded rect
    fill(txtColor); // text color
    textSize(16);
    textAlign(CENTER, CENTER);
    text(title, x, y-1, w, h);
  }
}

```

---

<div class="post-metadata">

**Author:** ![winterchan](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/winterchan/32/19921_2.png) [@winterchan](https://discourse.processing.org/u/winterchan)\
**Post date:** [August 18, 2024, 6:03pm UTC](https://discourse.processing.org/t/implementing-a-processing-app-inside-another-one/44920/23 "2024-08-18T18:03:32Z")

</div>

Thanks that is actually really useful  
for example i might make more games bigger and much more complex and that will be almost impossible just via processing

but… the question is , i am at the verge of finishing the game all i have is just embed some mini games into a window do you think it’s a good point to switch to eclipse for example?

---

<div class="post-metadata">

**Author:** ![LangdonS](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@LangdonS](https://discourse.processing.org/u/LangdonS)\
**Post date:** [August 18, 2024, 11:46pm UTC](https://discourse.processing.org/t/implementing-a-processing-app-inside-another-one/44920/24 "2024-08-18T23:46:26Z")

</div>

Well, it’s really up to you.

Java code runs faster than Processing and the executable file will be smaller, if you choose to distribute this game online.

---

<div class="post-metadata">

**Author:** ![LangdonS](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@LangdonS](https://discourse.processing.org/u/LangdonS)\
**Post date:** [August 19, 2024, 12:09am UTC](https://discourse.processing.org/t/implementing-a-processing-app-inside-another-one/44920/25 "2024-08-19T00:09:05Z")

</div>

Please note that getting P2D, P3D, and FX2D renderers to work outside of the Processing IDE is difficult.

(The default renderer–Java2D–works great)

[Previous page](https://discourse.processing.org/t/implementing-a-processing-app-inside-another-one/44920.md?page=1)
