# Only starting the main program when necessary?

**URL:** https://discourse.processing.org/t/only-starting-the-main-program-when-necessary/8397
**Category:** Libraries
**Created:** [February 14, 2019, 1:00pm UTC](https://discourse.processing.org/t/only-starting-the-main-program-when-necessary/8397 "2019-02-14T13:00:57Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Papergami45](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@Papergami45](https://discourse.processing.org/u/Papergami45)
#### Post date: [February 14, 2019, 1:00pm UTC](https://discourse.processing.org/t/only-starting-the-main-program-when-necessary/8397/1 "2019-02-14T13:00:57Z")

</div>

I’m working on a fairly complicated project involving multiple windows using G4P - the first window is the standard processing one, and the other two are a user interface window and a real time graph.

In order for the project to work, the user has to be able to interact with the interface window (putting in data for the program to use), and then pressing a “run” button. Upon this press, the main window should start running (setup, then draw, etc).

I honestly don’t know how to get this to work even in concept - as far as I know, the only way to start running processing code is from the main setup function, but this contains code that requires data the user should input from the other window… which as far as I know, can only be launched from the main setup code - agh!

Effectively, I’m stuck. I’m not sure how to get this working at all, and I really don’t have time to rebuild and restructure the entire project. Is there a way to say “only start running setup and draw once this thing has happened”?

---

<div class="post-metadata">

### Author: ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)
#### Post date: [February 14, 2019, 5:23pm UTC](https://discourse.processing.org/t/only-starting-the-main-program-when-necessary/8397/2 "2019-02-14T17:23:27Z")

</div>

Sure, you could use Processing as a Java library and only instantiate the sketch class when your criteria has been met.

Shameless self-promotion: here is a guide on using Processing as a Java library:

> **[Processing in Java](https://happycoding.io/tutorials/java/processing-in-java)**
>
> Learn how to use Processing as a Java library.

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [February 14, 2019, 5:37pm UTC](https://discourse.processing.org/t/only-starting-the-main-program-when-necessary/8397/3 "2019-02-14T17:37:28Z")

</div>

You can hide the Processing’s main window and pause it w/: 🕶

```java
getSurface().setVisible(false);
noLoop();

```

In order to show it and resume the window: 🏃‍♂️

```java
getSurface().setVisible(true);
loop();

```

---

<div class="post-metadata">

### Author: ![Papergami45](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@Papergami45](https://discourse.processing.org/u/Papergami45)
#### Post date: [February 15, 2019, 1:15pm UTC](https://discourse.processing.org/t/only-starting-the-main-program-when-necessary/8397/4 "2019-02-15T13:15:13Z")

</div>

For this project I doubt I’ll have time for a rethink of those proportions - however, I will keep it in mind for later projects, using Processing in that way seems super extensible and useful. Thanks a lot for the tutorial + link, it’ll help me out a lot.

---

<div class="post-metadata">

### Author: ![Papergami45](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@Papergami45](https://discourse.processing.org/u/Papergami45)
#### Post date: [February 15, 2019, 1:17pm UTC](https://discourse.processing.org/t/only-starting-the-main-program-when-necessary/8397/5 "2019-02-15T13:17:49Z")

</div>

Thanks a lot, I’ll see if I can implement this
