+ 1

Java Running Loop

I want to learn how to run a loop without waiting the inner loop to finish looping. cuz i have a 2 rect inside jpanel, then i also have 2 Jbutton 1 button will loop the rect1 and move from left to right every 1 px, then i click the button 2 but the rect 2 doesnt move at all, it just waits for the rect1 to reach the right portion of the jpanel. I think its the loop what i wanted to happen is that i can click rect 1 and start animating going to the right and i also can move rect2 to the right without waiting for rect 1 to finish moving how can i do that?

22nd Apr 2019, 4:44 AM
Jerbee Paragas
Jerbee Paragas - avatar
1 Respuesta
+ 2
What would be the expected behavior of your program, if the outer loop executes in parallel to the inner loop... ? E.g. for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) System.out.print(j); Do you just want two loops which can execute in parallel, instead of nested loops? Multithreading, with each loop in different threads, so that two loops execute together? https://www.tutorialspoint.com/java/java_multithreading.htm
22nd Apr 2019, 4:55 AM
Fermi
Fermi - avatar