+9

How to halt a java program until a method is called successfuly?

---BACKGROUND-- I'm doing a big project at the time - it can deal with history logs of a game. In that project I created a method which returns logs within a given time - and it works very well. I decided to create a UI for that program. Also I added a button which popups a JPanel to select date ranges - there's the problem start. --PROBLEM-- The popup pops out successfuly upon a butn click and user can select the date and submit. But I have methods which evaluates after that. What the problem is that the data from the popup is not submitted properly to the main program. I just debugged to find out what was happening. Then I found that the following methods evaluates before the popup pops out. --QUESTION-- My question is how to halt the program until the user submits the dates and then again start the program. I m looking for a way like JS promises.

6/12/2019 1:36:43 PM

Sεηιrυ ραsαη

3 Answers

New Answer

+4

Sεηιrυ ραsαη Not your answer but take a look at SwingUtilities invokeAndWait function. And probably you need to create a new thread (as you are already on Event dispatch thread) on button click to show JPanel. Note: I have not done swing programming since quite long so it is as good as i don't know anything, but few things you do remember 😉

+2

after you submit you can wait() or sleep() . look into those functions . use them with while statement like while( finishTarnsmit()==false) (new thread).sleep(100)

+2

Belal Al-Qudah I think I have forgotten to mention this. The code below the popup invokes before the picker pops out