Results 1 to 3 of 3
  1. #1
    Atriamax is offline Member
    Join Date
    Sep 2009
    Posts
    41
    Rep Power
    0

    Default wait() and notify() trouble with UI

    I have a program to copy images to another folder, and Im implementing a method to ask before overwriting an image of the same name. So in the loop of copying files, it checks if it already exists. If it does, then It displays a JDialog with the question. Since it checks in a loop, it has to use wait() to wait for the person to click the button. But whenever it hits the wait(), it does not update the images or the buttons on the JDialog until notified (which cant be done because you cant click on the button) even though im just using SetVisible(true) for the displaying of the dialog.
    How can i fix this?

    I know i might have to split it into two threads, but i dont know how i would do that with a jdialog.

    So in a nutshell, I need a way to run my loop, check for a problem, pause the loop, display a dialog to fix the problem, continue loop.

    thanks!

    ps: i have looked up quite a bit about wait() and synchronization, but i cant seem to find what im looking for.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    This is event-driven programming so you shouldn't have to call wait() and if you did call it on the EDT, you will freeze the EDT and your whole app. So just don't do it.

    Perhaps you want to check file existence first in a loop on your EDT and get the user input. Then after getting all the information you need, create a background thread (such as by using a SwingWorker object) and do your image file copying.

  3. #3
    Atriamax is offline Member
    Join Date
    Sep 2009
    Posts
    41
    Rep Power
    0

    Default

    bleh ill have to kinda rewire the loop but it should work, thanks.

Similar Threads

  1. wait() and notify() problems
    By greyradio in forum Threads and Synchronization
    Replies: 1
    Last Post: 08-03-2009, 03:36 AM
  2. Make a program notify
    By McChill in forum New To Java
    Replies: 7
    Last Post: 06-03-2009, 09:17 PM
  3. What is the execution path of wait() and notify() ?
    By AegisCruiser in forum Threads and Synchronization
    Replies: 1
    Last Post: 04-23-2008, 06:16 PM
  4. How to use sleep() to wait for a while
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-09-2008, 06:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •