How to pause enumeration while loop until button action?

Below is a chunk of code that uses a while loop to enumerate through a vector (LinkList) and does some processing on each element.  Part of this processing, is that it activates another window (dmdpanel1) that asks the user to provide some info about the item.  I need the enumeration while loop to stop and wait until after the ActionEvent on the new window is fired.  For the life of me, I can't figure out how to do this.  If I were looping through a recordset, I'd just use a for x = 0 to lenght loop and put the .MoveNext statement inside the button ActionEvent, but I can't figure out how to do somthing like this with a vector.  Here's the code:

    //now loop through the text vector and concactinate a string  of links for return
    Enumeration enum;
    LinkList = LinkExtractor1.getUrlTextUniqueVector();
    enum = LinkList.elements();
    while (enum.hasMoreElements ())
    {
      final String URLstring = enum.nextElement().toString();
      getURL getURL2 = new getURL();
      getURL2.strURL = URLstring;
      final String strContents2 = getURL2.getURLhttp();
      EkitCore.strURLSource = strContents2;
      final dmdpanel dmdpanel1 = new dmdpanel();
      dmdpanel1.strSource = strContents2;
      dmdpanel1.show();

      dmdpanel1.jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(ActionEvent e) {
          strType = dmdpanel1.strResType;
          try {
            ElementExtractor ElementExtractor1 = new ElementExtractor();
            ElementExtractor1.ElementExtractor(strContents2);
            String strPageTitle = ElementExtractor1.getTitle();
            EkitCore.strLinkList = EkitCore.strLinkList + "Link: " + URLstring + "  TITLE: " + strPageTitle + " Type: " + strType + "\n";
          } catch (Exception ex) {
            System.out.println("Error Updating Link List");
          }
          dmdpanel1.hide();
        }
          });
    }
wizcarlAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

OBCTCommented:
Make your show() method block by synchronizing it and making it wait...
E.g.

public synchronized void show()
{
  // show the frame
  while (isVisible())
  {
    try { wait(); }
    catch (Exception e) {e.printStackTrace(); }
  }
}

Then make your hide method notify the thread.
E.g.

public synchronized void hide()
{
  // hide the frame
  notifyAll();
}

If you are extending JFrame or any swing window, the setVisible() method already blocks saving you from implementing this yourself.
The setVisible() method will return only when dispose() has been called or the thread has been terminated.
wizcarlAuthor Commented:
I tried this, but I still can't make it work.  The 'try/catch' for the wait always throws the following error: "java.lang.IllegalMonitorStateException: current thread not owner"  It also jacks up my system memory and CPU usage which seems to run away.

Here's the code I'm now calling the window with which sits inside an enumeration while loop

While...

     final dmdpanel dmdpanel1 = new dmdpanel();
      System.out.println(EkitCore.strURLSource);
      dmdpanel1.strSource = EkitCore.strURLSource;
      dmdpanel1.setVisible(true);

      dmdpanel1.jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(ActionEvent e) {
          strType = dmdpanel1.strResType;
          dmdpanel1.dispose();
        }
      });
     

      while(dmdpanel1.isVisible())
      {
        try { wait(); }
        catch (Exception e) {e.printStackTrace(); }
      }

.loop

///////////////////////////////////////////////

Here's first line of the frame class that is being loaded.
      public class dmdpanel extends Frame implements HyperlinkListener  {

//////////////////////////////////////////////////

Again, I need to stop the enumeration loop until after either dmdpanel is not visible or the Button that the ActionEvent is listening too (which fires the dispose() method) is clicked.  This seems like such a basic task.  I'm sure that I must just be missing something obvious.

Thanx

Carl
OBCTCommented:
2 things...
1) Any code that calls wait, notify or notifyAll must be called in synchronized code.
So either the method must be synchronized or, you use something like this....
  synchronized(this)
  {
    while (somethingIsTrue)
    {
      try { wait(); }
      catch (Exception e) { e.printStackTrace(); }
    }
  }

2) Frame and JFrame (I should have said Frame in my last comment) have already implemented the setVisible method to block until the frame has been disposed.

All you need to do is remove this...

      while(dmdpanel1.isVisible())
      {
        try { wait(); }
        catch (Exception e) {e.printStackTrace(); }
      }

and everything will work fine.
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

CEHJCommented:
>>it activates another window (dmdpanel1) that asks the user to provide some info about the item.

If you make that window a modal JDialog or mount the panel as an owned object of a JOptionPane it will make the thread wait automatically for input

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wizcarlAuthor Commented:
This still does not actually work.  It did, however, provide me with enough information to figure out why it doesn't work.  When I synchronize the window opening event, the synchronization works such that the window is protected so that it can not be accessed by any other threads until it has run its course.  The problem seems to be that the compter is considering the enumeration iteratrions as a single thread since they run in sequence.  As such,the same thread is allowed to continually call the synchronized item.  I tried to synchronize the enumeration itself so that each loop of the enumeration would count as a seperat thread, but I couldn't make this work.  After spending close to to twenty hours trying to figure this out, I've just moved on and solved the problem for now with some brute force hacking and a change of UI.
CEHJCommented:
:-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.