objective c - Java equivalent of Cocoa NSNotification? -


I'm writing Java application using the SWT widget. I would like to update the status of certain events (for example, updating the status of the data model).

Is some cocoa similar to NSNotificationCenter in Java, where I can register something for the notification of notifications and respond to them, as well as other things "close" a notification?

OK, suppose for example, you want your program to be notified when your Loader scans start, and when this scan ends (do not worry about what the loader is or what the scan is, these examples are some of the codes I'm lying around from my last job) you define an interface It is called "ScanListener", like

  public interface Number Skanlist (public void Scan started); Public Zero Scan Full (); }  

Now the loader defines a method for your other code to be registered for the callback, such as

  Public Zero addScanListener (ScanListener listener } {Listeners.add (listener); }  

The loader, when this scan starts, executes the following code

 for  (Scanlist listener: listeners) {listener.scan start (); }  

And when it finishes, it does the same thing with listener.scan ();

Calls the code to be reported about these events either in the interface itself or in the internal category), and call "loader.addScanListener (this)". Its scanned starred () and scanned full () methods are called at the right time. You can also do this with a callback that results in logic and / or returns. It all depends on you.


Comments