Cp5 GUI; function runs before new window shows up

Hi everyone, I am new to processing and coding in general. I’m trying to make Software for an automatic liquid handling station and the most of it is working.

But: I have a GUI with a “Start” Button. When you click on it the EventController should close the Window and open the next, before the program is carried out. But it runs the program first and after finishing opens the new window. So I tried to set a boolean variable on true, when the EventController gets the event and start the program with that, but it was not working…Do you have any ideas, how to fix it?

so this is how this part looks:

cp53 = new ControlP5(this);

case 5: //start program
programm(Pipette, GefäßLösung, GefäßProben, SpitzeWechseln, e_auf1, Pipettiervolumen, VolumenLösung, Probenanzahl,faktor);
if(schrittzwei == true){//wenn 2 Schritte ausgewählt
programm(Pipette, GefäßLösung2, GefäßProben, SpitzeWechseln2, e_auf2, Pipettiervolumen2, VolumenLösung2, Probenanzahl,faktor);