Waiting until a gui frame finishes.

Hi, I'm trying to implement something like JOptionPane or JFileChooser, where if you invoke methods of those classes to show GUI windows your program stops executing until the user click OK or something like that. I've been trying to implement this sort of functionality, but I'm getting nowhere at all with this. I'd like to implement something like this so that I wouldn't have to create call back methods in my program to be used by the GUI window when it's done, since that's a dirty way of doing it. Any help would be appreciated. Thanks.

Use a modal JDialog. Read the JDialog API for more info.

Similar Messages

  • Code to wait until one event is finished before starting another?

    Hi all,
    Coding isn't my strong point but I have a basic understanding of how functions etc work.
    I've been learning about referencing symbol timelines with the awesome tutorial from the Adobe Blog, included below.
    http://blogs.adobe.com/edge/2012/07/18/tutorial-leveraging-independent-symbol-timelines/
    I've been able to get my symbol to play from a certain part of it's timeline depending on whether the mouse is rolling in or out but now I'm a little bit stuck.
    The mouseover event triggers an animation and the mouseout triggers another animation that starts from the same frame that the mouseover animation ends with.
    The problem is this. If I move the mouse quickly over the buttons, the first animation will play halfway through and when the mouseout triggers the second animation, the first animation will seemingly "skip" to the ending and move straight to the first frame of the second animation.
    I know enough to code it so that the second animation will check if the first animation is still playing before starting by using an else/if statement. Using this method I only know how to skip the second animation if the first is playing but that isn't really what I'm looking to do.
    Here comes the question; can anyone explain to me how to create a wait loop in Edge Animate?
    When I say wait loop, I am talking about code that will check a variable and perform an action if the variable is true OR loop back to the start of the function if the variable is false (to check the variable again).
    The behavior I am trying to achieve is somewhat like queuing the second animation so that it will "wait" until the first animation is played before beginning the second animation.
    Any ideas?

    Ok Mr Doon,
    Clearly, I read to quickly
    The behavior I am trying to achieve is somewhat like queuing the second animation so that it will "wait" until the first animation is played before beginning the second animation.
    So, say the anima symbol is a 2s animation and has autoPlay set to false. There are two instances anima-1 and anima-2 on stage.
    The event handler anima-1.mouseover starts the first animation :
    We select Stage in the code panel and place before the first Symbol.bind… the declaration for two symbol (stage) variables :
    Inside the anima timeline, click the top left bullet+curly brackets icon and select complete : when the animation is complete, we set the boolean variable (what is not very clean here is that this is done for the two instances anima-1 and anima-2) :
    The event handler anima-2.mouseover starts the wait loop, by calling a function defined at the stage level :
    More precisely, the function is defined in the document.compositionready handler. It defines (and stores in variable waitLoop in order to be able to remove when finished) an interval, that is the repeated call, every 10 ms, of an inner anonymous function.
    The latter simply tests the boolean and when its true
    - starts the second animation ;
    - clears the interval.
    You can download the example here : https://www.box.com/s/6yxjfmrqd0b5zbhmd3lx
    You can hover over the left rounded rectangle, and immediately after over the second one. Subsequent rollovers are not handled, but it gives you a possible logic to adapt to your particuliar problem (that I still do not understand completely : it's hard without seeing).
    Gil

  • How to wait until setPage(number) is finished

    SR 3-8311228061
    When calling getStrings, found I need to iterate the pages of the doc/xls/etc
    However Autovue Support tells me that setPage() is asynchronous
    I asked how to wait until setPage() is complete, they suggested I post the question here
    Note, at the time its called the viewer (desktop version 20.2.2) is on the task tray, but not rendering the document
    Its only loaded to extract the text
    here is the blip of code
    for( curPage = 1; curPage <= pages; curPage++)
    vueBean.setPage( curPage ); //its necessary to call setPage even for page 1
    //If setpage fails stop (per Daniel/Oracle)
    int thisPage = vueBean.getPage();
    if( curPage != thisPage )
    //This message never shows up
    String msg = String.format("Pages[%d] thisPage[%d] curPage[%d] ", pages, thisPage, curPage);
    AdeptApplication.INSTANCE.publishEvent("file-event", msg,
    new SystemEvent(this.fileName, "GETTEXT_PAGEFAILED"));
    break;

    The code you have is to know whether changing pages succeeded or not, and unless you are trying to set a page number that is out of the page count it will always succeed
    So, yes, your test is the same as if (false)
    Now, page loading is done in an asynchronous manner
    1. you ensure that the page (the container for all the page artifacts) is created, synchronously
    2. the page content are streamed on another thread
    3. once the page is loaded, an event is sent VueEvent(VueEvent.FILEEVENT, VueEvent.ONPAGELOADED)
    So you should be able to query for info after you received the page loaded event
    Now, word documents are an special kind of documents, so you need to be aware of some specific issues.
    The same way ms-word does not know the total number of pages until the ENTIRE document is loaded, AutoVue will not be able to notify you either.
    And as Word, AutoVue allows you to display the pages that are already loaded, and you may query for some of its contents too.  BUT you can not query for page info when the page is been loaded (or obviously not yet loaded)
    The loading is a 2 phase one, part is done on the server (native code) and part is on the java side (display)
    So you will not be able to iterate
    for( curPage = 1; curPage <= pages; curPage++)
    simply because page count is not known.  You need to query doc info more than once.
    If page count = -1, you need to iterate for each page and then, test whether setPage() != getPage() and/or page count has been updated.

  • How can I wait until a Swing.Timer has finished?

    I have a Swing.Timer runing which displays some animated text (more precisely it fades out a text with a delay of 50 until all characters are erased.
    Afterwards a time consuming operation shall begin. How can I achieve that this operation waits to start until the text has been faded out? The time to fade out the text depends on the length of the text, of course.
    So, how can I make the operation waiting until the Timer has finished its work?
    Thanks,
    Dirk

    dirku wrote:
    I have a Swing.Timer runing which displays some animated text (more precisely it fades out a text with a delay of 50 until all characters are erased.
    Afterwards a time consuming operation shall begin. How can I achieve that this operation waits to start until the text has been faded out? The time to fade out the text depends on the length of the text, of course.
    So, how can I make the operation waiting until the Timer has finished its work?I gave you an answer to this with sample code yesterday:
    [http://forum.java.sun.com/thread.jspa?threadID=5294087&messageID=10244564#10244564|http://forum.java.sun.com/thread.jspa?threadID=5294087&messageID=10244564#10244564]
            public void actionPerformed(ActionEvent e)
                if (sb.length() > 0)
                    sb.deleteCharAt(0);
                    label.setText(sb.toString());
                else
                    label.setForeground(color);
                    label.setText(text);
                    Timer timer = (Timer)e.getSource();
                    timer.stop();
                    // ***** start process here ***
            }The timer here continues until a condition is satisfied (here it's where the Stringbuffer that holds the text that is sent to the JLabel is empty). So all you have to do is place any code that needs to happen when the Timer ends in the else block. It's so simple as to be trivial.

  • Waiting for the GUI assembling...

    How can I wait by my GUI assembling ?
    the problem is: I have a heavy GUI loading in an JApplet and a fast maximum flow calculus to be done....
    currentlly, the calculus had been finished before the GUI becomes visible.
    I want that method which calculate the flow waits until the GUI is visible to the user....
    I know that exists a default Swing manner of do it.. but I can�t figure it out....

              setSize(450,450);
              setVisible(true);
              Vector nodes = net.getVertices();
              System.out.println(net.maximumFlow((Vertex)nodes.elementAt(0), (Vertex)nodes.elementAt(nodes.size()-1)));The problem is: while the maximum flow is calculating, the lines representing the pipes in the reservoir system become colored and some visual data are changed..... (it is an animation representing the net flow behaviour...)...
    Actually, when the GUI appears, all the calculus have already finished and my animation is over.... only the last colored scene appears to the user.... That�s why I want to delay the calculus until the GUI is visible.
    startAfter ? postpone ?

  • How can i get program to wait until file is loaded?

    Hi all,
    I keep getting a null pointer exception error thrown when it shouldn't. I'm 99% certain that its being generated because the program speed is faster than the load file time. Is there any way to make the program wait until the file is finished loading? I know you can set up a for loop that will take up some time but I wanted it to be more accurate so that no errors will occur on any machine. Here is the code
    RunMainProg();
              String[] TempHolder = new String[HowMany*2];
              try
                  BufferedReader readerOne = new BufferedReader(new FileReader("TempMDLFile.txt")); // file just save from RunMainProg()
                  String lineOne;
                  int i=0;
                       while ((lineOne = readerOne.readLine()) != null)
                            if(i>=TempHolder.length)
                            break;
                             TempHolder=lineOne;
                             i++;
              readerOne.close();
                   catch (IOException f)
                        MakeDialog ErrorDialog = new MakeDialog(TopWindow, "Load Error", "Error - The file you entered does not exist", "Error", "OK", "OK", 0, 0);
                   for(int i=0; i<TempHolder.length; i++)
                        if(TempHolder[i] == null)
                        i=0;
                   FormatData TestSequences = new FormatData(TempHolder); // problem occurs at this line
    I have looked all over and can't seem to find a way to verify if the file is loaded, or to get it to wait until it has. Any help would be much appreciated. Especially if you can supply some code snippets :)
    Much obliged
    Drb2k2

    okay, I added some test code that I was using to try and iron out the problem. Perhaps its best if I run through what happens.
    1. I get the data from the text box, and an external program is run which generates some text files. These files are then loaded and examined and some new data is appended to the old. This is the process
    FormatData TestSequences = new FormatData(TempHolder); Now every time its run first time around its fine.
    2. When I try and do exactly the same thing with the new appended set of data the null exception is thrown. Now Dr Clap, I thought exactly the same as you did, but... If i add the following bit of code before the FormatData call..
    for(int i=0; i<TempHolder.length; i++)
    System.out.println(TempHolder);
    It will produce the data without the appended info, and some null sequences.
    The size of TempHolder is adjusted depending on the amount of data submitted, so somewhere along the line its just not working.
    3. Now for the fun part, eventually if you put the call in a loop it will correct itself and produce the outcome, but needless to say i'd rather not have my program catching a load of nullpointerException errors.
    Finally as for the code
    for(int i=0; i<TempHolder.length; i++)               {                    if(TempHolder[i] == null)                    i=0;               }That was an attempt to stall the program until no null sequences were found. Sort of getting around the problem in 3.
    Dr Clap is a legend on these posts and his advice is well recieved but I have no idea how to view a stack trace or what benefit it has. Any tips on this would be great.
    Thanks for your help so far
    drb2k2

  • HT1923 HI...trying to uninstall iTunes components, but get the error that another program is trying to install..wait until it's finished then try to install. Install? I clicked UNinstall! Nothing is installing!?!?!?! HELP!

    Hi,
    Getting Runtime Error 6034. When I attepmt ot follow the suggetions to rectify this issue, I get the erroe message that anothe program is tryin to install. Wait until it's finish and try install again. 'Install'????? I clicked UNinstall!!! How can I find if something is trying to install? I am not installing anything. HELP!!!! PLEASE!!!!

    I get the erroe message that anothe program is tryin to install. Wait until it's finish and try install again.
    Restart the PC. Can you complete the uninstalls now, or do you still get the message?

  • Is there any way to call a sub vi which has input parameters and not wait until it finishes executing?

    Hi,
    I have a main vi that I would like to call a sub vi from and have the main vi continue on without waiting for the sub vi to finish. I can open a reference to the sub vi and invoke the "run" method, but in this fashion, I cannot pass any parameters to the sub vi. Or, I can use a call by reference node where I can pass parameters, but there is no option to not "wait until done". How can I do this? Is global variables the only way?
    Thanks!

    Use the method Set Control Value before you invoke Run. You specify the exact name of the control and the data you want to pass needs to be flattened to a string.

  • When i try to close my iPhoto app on my air it continuously says wait until import is finished and it won't let me exit the app, what can i do to close it?

    when i try to close my iPhoto app on my air it continuously says wait until import is finished and it won't let me exit the app and i cant even turn off my laptop, what can i do to close it?

    Welcome to Apple Support Communities
    Press Alt, Command and Esc keys or go to  > Force Quit, choose iPhoto and force close it.

  • Have system wait until GUI is completed

    I wrote a program to monitor a seniority list. If an odd last name, first name, etc is encountered, a gui opens to request the proper form of the name. The problem is that the program keeps running even though the gui has not yet been fililed out. How do I stop execution until the GUI is completed?
    Thanks
    Joe

    Make the dialog modal.

  • How to wait until the 1st part of the processing is done

    Hi,
    I had a hard time to combine two parts of processing in one .vi file, and thus would like to get some advice/help through the forum.
    Attached is the partial finished vi file I made. You can see that it is composed of two parts. The upper part is to run a bat file (check_result.bat), which generates a result.txt file. The lower part is to use the result.txt file as an input file, and check if the key word called "test case passed" is included in the result.txt file or not. So I want to run the upper part firstly, and then run the lower part after the upper part is finished.
    However, I don't know how to connect the two parts in a right way that the lower part only starts running after the upper part is finished. Any comments/help is highly appreciated.
    Thank you in advance.
    Xuedong 
    Attachments:
    question.vi ‏49 KB

    The magic of dataflow!
    All you need is a data dependency between the two parts. Often critical parts of each section contain error terminals, so you can just string em along in the proper order and each part must wait until the previous node has finished.
    In your particular case, the read operation has no error input, so you can recruit any other input. Create a fake data dependency by strategically placing a small sequence frame containing common code. The sequence cannot start until all code that provides imputs has finished, serving your purpose.
    Of course it seems silly to even try to read the file if the previous node failed. Right? So simply place the second part inside a case and hook it up to the error output. Now the second part (1) waits until the first part has finished AND (2) execute only of the first part succeeded. No sequence needed.
    All clear?  
    Message Edited by altenbach on 02-07-2007 02:34 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    dataflow.gif ‏4 KB
    dataflow2.gif ‏4 KB

  • Wait Until Next ms Multiple.vi explanation

    altenbach, 
    Great examples!!! 
    I am using an
    older code that place a “wait until next ms multiple.vi” in a time loop.
    From the feedback
    I am getting on the forum, I think I should use CONSUMER AND PRODUCER
    ARCHITECTURE TO GATHER THE data. BUT for me to get more time for the project I would
    have to explain why the current codes need to be changed.
    The only thing
    that change in this code when I run it at a smaller distance( angles smaller
    than .72) and bigger distance (angles greater than .72 ) are the timing for the
    “wait until next ms multiple.vi.”  Inside
    the time loop I measure the time it take for the wait until ms to finish.
    I had run the
    code when the angle was smaller than .72 and printed out the Boolean status for
    each iteration. And when it was bigger than .72. if interested I have attached
    the file. There is no different. The different is only with the timing!!!
     

     
    sticyfinger wrote:
    I am slow. Can you please elaborate on that some more? Sound
    interesting.  Think that may be related
    to what happen to my code. When I measure smaller distance I have to use bigger
    numbers for the wait. 
    Please elaborate how you are measuring. A wait controls, and does not measure, timing. What happens in the code during the wait? How do you measure?
    In a nutshell, here are some semi-true analogies:
    Wait until next ms multiple
    Do something every hour on the hour (60 minutes multiple), i.e. wait until the minute hand points straight up. If your task takes 30 minutes, you get a 30 minute break, if the task takes 50 minutes, you can only take a 10 minute break. If your task takes 61 minutes, you get a 59 minute break, but might lose your job because you missed an assignment.
    The first wait is random between 0 and 60 minutes and depends on the time you arrive at the job site.
    If the wait is in a loop, the first iteration takes between 0 and x ms. All subsequent iterations are equally spaced unless your code cannot complete in the allocated time.
    Wait(ms)
    No matter what time it is, wait 60 minutes before continuing. This is often somewhat clouded by the parallel nature of LabVIEW. For example if a wait(ms) is in a loop, the iteration cannot complete until at least x ms have elapsed. However the timer starts in parallel with the other operation in the loop, so even if the operations take a significant amount of time, it won't artificially prolong the loop. However, if you would use a sequence such that the wait is in the last frame, the loop time will be the sum of the code time and the wait time. And so on....
    All waits are the same, and independent in when you arrive at the job site.
    If the wait is in a loop, all iterations will be approximately x ms unless your code cannot complete in the allocated time. Over time, there could be slight drift due to accumulations of small errors caused by the delay between the loop start and scheduling of the wait node.

  • How can I prevent the flushing of the buffer until the playing is finished in AS3?

    How can I prevent the flushing of the buffer until the playing is finished in AS3?
    Is it possible?
    The buffer is emptied and flushed 10-11 seconds before the real end of the flv file.
    The file is locally saved and I stream it though crtmp server.
    I cannot seek the last 10 seconds because of empty buffer. How can I stop flash from flushing the buffer at end?

    i used the same code and i got it working correctly...
    thanx a lot fot it...
    now i have one more problem with it.
    Actually i created a new class 'ErrorDialog' and the function showErrorDialog() inside it.
    now i want the option YES_NO_OPTION and the function sayshowMsgDialog() returning int value indicating the option selected from the dialog box.
    I tried it with following code
    public
    static
    int
    confirmDialog( String message_in, Component parent_in, String title_in,
    int messageType_in )
    try
    JOptionPane pane = new JOptionPane( message_in, messageType_in,
    JOptionPane.YES_NO_OPTION );
    JDialog dialog = pane.createDialog( parent_in, title_in );
    dialog.setResizable( false );
    dialog.show();
    int optionType = -1;
    try
    optionType = ( ( Integer )( pane.getValue() ) ).intValue();
    catch( Exception ee )
    optionType = -1;
    dialog.dispose();
    return optionType;
    catch( Exception e )
    e.printStackTrace();
    but, since return is after dispose() it is throwing an error 'missing return value'
    can i get some kind of solution for this?
    waiting eagerly...........
    -Soni

  • File Adapter -- Picking has to wait untill it get fully loaded/write.

    Hi All,
    I need to pick the files from a folder and I need to pick the files only which has been written completely.
    I should not pick the file in the middle while writing, I need to wait untill it finishes the writing completely.
    Is there any setting I can put in Sender File adapter to do this?
    Thanks
    Seema

    Nithya,
    >> Try to increase the processing time in the sender communication channel, so that it allows you to completely load the file. Check the time which is needed to upload the file to the directory manually and correspondingly change the processing time.
    We do not know exactly at what time the file will be placed in the folder. It may be at any time. So I cannot put the processing time accurately.
    Aamir,
    >> If you are picking from FTP,MSecs wont work there.the sender program which writes the file must write the file in some temporary format like .dat etc and once the file is complete it should change the filename to .txt,configure the sender file adapter to pick only *.txt files.
    This is a good idea. But I don't think I can ask them to change at the other end as it is working previously with other middleware.
    Guys,
    Can you please advice which is the best thing we can do at this point of time.?
    Thanks
    Seema.

  • Waiting for a thread to finish

    I've been researching this issue for a couple of days, but I dont think I know enough about threading to ask the right question in a search engine. Sorry if this is a basic blunder....I dont write swing often and it shows.
    I have a swing app that includes a long task so I have implemented a progress bar. I need to wait until the progress bar task completes before continuing to the rest of the method. I've tried:
    1. Putting the progress bar within a while loop (while task not complete...) but the progress bar dialog does not render fully. I've even added repaint, but still the dialog looks blank.
    2. SwingUtilities.invokeLater, but it doesnt wait until the progress bar is finished
    3. SwingUtilities.invokeAndWait, though after all the reading I did about deadlock conditions I didnt like the idea. However I was desperate so I tried it and got an error:"Cannot call invokeAndWait from the event dispatcher thread".
    4. Putting the code that needs to occur after the progress bar in an "invokeLater" thread
    5. I've also used the ProgressBarDemo from the java.sun example with the swingworker hoping the worker thread would handle the issue.
    A much smaller version of the code is below:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.Border;
    public class ProblemCode extends JFrame
         private JFrame jFrame = null;
         private JPanel jMain = null;
         private JButton startButton = null;
         public ProblemCode()
              initialize();
         public void initialize()
              //Setup the main application window size
              jFrame = new JFrame();
              jFrame.setContentPane(getJMainPanel());
              jFrame.pack();
              jFrame.addWindowListener(new java.awt.event.WindowAdapter()
                   public void windowClosing(java.awt.event.WindowEvent e)
                        dispose();
              SwingUtilities.invokeLater(new Runnable()
                public void run()
                    jFrame.setVisible(true);
         private JPanel getJMainPanel()
              if(jMain == null)
                   jMain = new JPanel();
                   jMain.add(getJStartButton());
              return jMain;
         private JButton getJStartButton()
              if (startButton == null)
                   startButton = new JButton();
                   startButton.setText("Start");
                   startButton.setVisible(true);
                   startButton.addActionListener(new ActionListener()
                       public void actionPerformed(ActionEvent e)
                           SwingUtilities.invokeLater(new Runnable()
                                 public void run()
                                          progBar();
                            System.out.println("Do this after the progress bar completes");
                            SwingUtilities.invokeLater(new Runnable()
                                 public void run()
                                      System.out.println("invokeLater doesnt work either....");
              return startButton;
         private void progBar()
            JFrame jProgFrame = new JFrame("JProgressBar Sample");
            jProgFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            Container content = jProgFrame.getContentPane();
            final JProgressBar progressBar = new JProgressBar();
            new Thread()
                private int counter = 0;
                private final int val = (int)(Math.random()*10)+1;
                public void run()
                    for(int i = 0;i <= 100;i++)
                        counter += val;
                        javax.swing.SwingUtilities.invokeLater( new Runnable()
                            public void run()
                                progressBar.setValue(counter);
                        try
                            Thread.sleep(500);
                        catch (InterruptedException e)
            }.start();
            progressBar.setStringPainted(true);
            Border border = BorderFactory.createTitledBorder("Reading...");
            progressBar.setBorder(border);
            content.add(progressBar, BorderLayout.NORTH);
            jProgFrame.setSize(300, 100);
            jProgFrame.setVisible(true);
         public static void main(String[] args)
              SwingUtilities.invokeLater(new Runnable()
                   public void run()
                        new ProblemCode();
    }Thank you for taking the time to review this.

    Hi,
    I made some tiny changes in yoyr code, marked with
    // PBHere the changed code
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.Border;
    public class ProblemCode extends JFrame {
        private JFrame jFrame = null;
        private JPanel jMain = null;
        private JButton startButton = null;
        public ProblemCode() {
         initialize();
        public void initialize() {
         // Setup the main application window size
         jFrame = new JFrame();
         jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // PB
         jFrame.setContentPane(getJMainPanel());
         jFrame.pack();
         jFrame.addWindowListener(new java.awt.event.WindowAdapter() {
             public void windowClosing(java.awt.event.WindowEvent e) {
              dispose();
         SwingUtilities.invokeLater(new Runnable() {
             public void run() {
              jFrame.setVisible(true);
        private JPanel getJMainPanel() {
         if (jMain == null) {
             jMain = new JPanel();
             jMain.add(getJStartButton());
         return jMain;
        private JButton getJStartButton() {
         if (startButton == null) {
             startButton = new JButton();
             startButton.setText("Start");
             startButton.setVisible(true);
             startButton.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                  SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                       progBar();
                  System.out
                       .println("Do this after the progress bar completes");
                  SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                       System.out
                            .println("invokeLater doesnt work either....");
         return startButton;
        private void progBar() {
         JFrame jProgFrame = new JFrame("JProgressBar Sample");
         jProgFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         Container content = jProgFrame.getContentPane();
         final int val = (int) (Math.random() * 10) + 1; // PB
         final JProgressBar progressBar = new JProgressBar(0, 100 * val); // PB
         progressBar.setStringPainted(true);
         Border border = BorderFactory.createTitledBorder("Reading...");
         progressBar.setBorder(border);
         content.add(progressBar, BorderLayout.NORTH);
         jProgFrame.setSize(300, 100);
         jProgFrame.setVisible(true);
         // PB
         final Thread longTask = new Thread() {
             private int counter = 0;
             public void run() {
              for (int i = 0; i <= 100; i++) {
                  counter += val;
                  javax.swing.SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                       progressBar.setValue(counter);
                  try {
                   Thread.sleep(100); // PB
                  } catch (InterruptedException e) {
         longTask.start();
         // PB
         Thread followUpTask = new Thread(new Runnable() {
             @Override
             public void run() {
              try {
                  System.out.println("Follow up task is waiting");
                  longTask.join();
                  System.out.println("Follow up task  continues");
              } catch (InterruptedException e) {
                  e.printStackTrace();
         followUpTask.start();
        public static void main(String[] args) {
         SwingUtilities.invokeLater(new Runnable() {
             public void run() {
              new ProblemCode();
    }Piet

Maybe you are looking for