• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

setCallBack method in swing

Could some one explain me about setCallBack method in swing
0
srivenky
Asked:
srivenky
2 Solutions
 
TimYatesCommented:
Yes....  there isn't one...

At least not in the standard Swing components...  Are you using a component written by someone else?
0
 
thanassisCommented:
if you define a callback ...

class Callback implements CallbackTarget {
     public action(Subscription sub, Notification notif) {
        System.out.println(notif);
    }
}

...you can use the setCallBack method as follows:

callback = new Callback();
sub = new Subscription("exists(CoffeeBiff)");
sub.setCallback(callback);
0
 
srivenkyAuthor Commented:
If you could explain me the concept behind it, it would be more useful.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
TimYatesCommented:
Say you define an interface:

---------

interface GuffCallback
{
  public void doSomething( String woo ) ;
}

---------

Then, you can make another class that will call you back when it is done (in this case, a threaded object)

---------

public class ThreadedObject implements Runnable
{
  volatile Thread runner = null ;
  GuffCallback whenDone = null ;

  public ThreadedObject()
  {
  }

  public void setCallback( GuffCallback cb )
  {
    whenDone = cb ;
  }

  public void start()
  {
    if( runner == null )
    {
      runner = new Thread( this ) ;
      runner.start() ;
    }
  }
 
  public void run()
  {
    // do something that will take some time...
    try{ runner.sleep( 30000 ) ; } catch( InterruptedException ex ) {}
    if( whenDone != null )
    {
      whenDone.doSomething( "DONE IT!!" ) ;
    }
  }
}

---------

Then, you make your main class implement that interface, and create the thread thing to call you back...

---------

public MyMainClass extends JFrame implements GuffCallback
{

  ....
  // required for the interface...
  public void doSomething( String woo )
  {
    System.out.println( "Something called with parameter " + woo ) ;
  }
  ...

  public void doIt()
  {
    ThreadedObject obj = new ThreadedObject() ;
    obj.setCallback( this ) ;
    obj.start() ;
  }
}

---------
0
 
CleanupPingCommented:
srivenky:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
srivenkyAuthor Commented:
please delete this question
0
 
girionisCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Split points between thanassis and TimYates

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

girionis
EE Cleanup Volunteer
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now