• Post Reply Bookmark Topic Watch Topic
  • New Topic

Program to sleep until applications existence.  RSS feed

 
Pallavi Mahajan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everybody,

I want to write a program which will wait till application panel will be open or existed and then I want to start performing IO. In our application, there are many panels invokation from paren panels, so it takes time to open child panel, so I want to wait till child panel opens and then start performing IO. How can I do that?
Please guide me.
Thanks
Pallavi
 
Petr Blahos
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pallavi,

I am afraid your question is a little bit too vague. Do you
have an application with a swing or AWT GUI? One thread creates
the panels and another thread does I/O and you want to delay the
execution of "the I/O" thread?
Or do you have 2 applications communicating?
Or is it something else?

What about this? Start the I/O thread from the thread that
creates the panel after the panel is created.

Best regards,
Petr
 
Pallavi Mahajan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter,
Sorry for vagueness.
Ok here is complete picture.
We have Swing GUI (Application) and right now I'm automating that.
While doing that when I click on one button it opens another panel and I have to perform actions on the newly opened panel. So I want to add delay, I want my automation to hold on till new child panel opens...once it is open I was to perform various actions on it but I do not want to add static delay...I want to know when that child window has completely loaded.

Thanks,
Pallavi
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Working in Swing you're familiar with listeners? You can use the same kind of listeners and events to communicate with your own objects. When your panel finishes loading it can fire an event for all interested listeners and one of those (the only one) can start its background work.

Look at Observable and Observer in the JavaDoc. Let us all know if that's enough to go on or if you'd like more details.

For another direction, are you comfortable with threads? They are not always the right answer, but it just might help to run your long-running process on its own thread.
 
Pallavi Mahajan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Stan,

Yes I'm familier with listeners. I will look into Observable/Observer.
I have tried using Thread.sleep() but I guess it was not a perfect method.
Still if you wont mind and can write in little much detail about how to implement Observable/Observer it will be really nice...I will keep on working though...thanks,

Pallavi
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In short, you want the window you're waiting on (observable) to have a reference to the object that's waiting (observer). When the time comes, observable calls an method on observer. That method can start the process that's been waiting. See if this makes sense:

Create the observer first. It implements Observer.

Create the window next. It should have a variable holding an Observable.

Add the observer to the Observable. You might do this in the window's constructor: myObservable.addObserver(arg0);

Do the window's long-running initialization.

When that's done, set Observable's hasChanged to true and call myObservable.notifyObservers.

The observer's update() method is called. It starts the process we've all been waiting for.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!