# Multiple functions under one

**URL:** <https://discourse.processing.org/t/multiple-functions-under-one/42698>\
**Category:** Coding Questions\
**Created:** [September 4, 2023, 9:21pm UTC](https://discourse.processing.org/t/multiple-functions-under-one/42698 "2023-09-04T21:21:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![E142](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@E142](https://discourse.processing.org/u/E142)\
**Post date:** [September 4, 2023, 9:21pm UTC](https://discourse.processing.org/t/multiple-functions-under-one/42698/1 "2023-09-04T21:21:59Z")

</div>

So I’m trying to build a menu button that has three options and I want whenever an option is selected a certain program runs. So each program has a multiple functions like 3 to 4 function, so I’m finding it difficult to put all these functions on that one function so when option one is clicked Program 1 runs. In processing you can’t multiple functions inside one for some reason.

---

<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:** [September 4, 2023, 9:29pm UTC](https://discourse.processing.org/t/multiple-functions-under-one/42698/2 "2023-09-04T21:29:33Z")

</div>

> [@E142](#):
>
> In Processing you can’t multiple functions inside one for some reason.

Main Processing flavor is based on Java.  
Java prefers to encapsulate multiple functions as 1 `class`:

> **[Objects / Examples](https://processing.org/examples/objects.html)**
>
> Move the cursor across the image to change the speed and positions of the geometry. The class MRect defines a group of lines.

> **[What Is a Class? (The Java™ Tutorials \>        
            Learning the...](https://docs.oracle.com/javase/tutorial/java/concepts/class.html)**
>
> This beginner Java tutorial describes fundamentals of programming in the Java programming language

---

<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:** [September 5, 2023, 12:20am UTC](https://discourse.processing.org/t/multiple-functions-under-one/42698/3 "2023-09-05T00:20:31Z")

</div>

Have you considered using a menu bar or other Swing component?  
[https://discourse.processing.org/t/swing-components-in-default-processingwindow/35483](https://discourse.processing.org/t/swing-components-in-default-processingwindow/35483)

 ![swing](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/5/a/5a9972d923dad262250395567d63b110fa66d07b.png)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [September 5, 2023, 9:52am UTC](https://discourse.processing.org/t/multiple-functions-under-one/42698/4 "2023-09-05T09:52:03Z")

</div>

Always best when you show your entire code so we can take  
a look.

Anyway when you are a beginner, just set an int variable myCommand (or whatever name) from the buttons to 0, 1 or 2 (or when the button has a unique id, just use this) and in the function use switch(myCommand) {… or use if(myCommand==0){…

So you can execute different code in one function depending on the button
