Cocoa NSNotification Java equivalent?

I am writing a Java application using SWT widgets. I would like to update the state of some widgets on a specific event (for example, update the state of a data model).

Is there something in Java similar to Cocoa NSNotificationCenter where I can register an object to listen to notification events and respond to them, as well as other objects to β€œhide” the notification?

+5
source share
7 answers

Well, suppose you want parts of your program to be notified when your bootloader starts scanning, and when it finishes scanning (don't worry about what Loader is, or about what scanning, these examples are from some code that I lay from my last job). You define an interface, call it "ScanListener", for example

public interface ScanListener
{
  public void scanStarted();
  public void scanCompleted();
}

Loader now defines a method for your other registration code for callbacks, for example

public void addScanListener(ScanListener listener)
{
  listeners.add(listener);
}

The bootloader, when it launches a scan, executes the following code

for (ScanListener listener : listeners)
{
  listener.scanStarted();
}

and when it ends, it does the same with listener.scanCompleted ();

, , ( , ), "loader.addScanListener(this)". scanStarted() scanCompleted() . , / . .

+8

? , - ", , ", - Observer Observable. , , , .

+2

, java, NSNotificationCenter. java , ( , ), . , , ( * * EventListener AWT Spring).

. Paul, java.util.Observable, , , . java.beans.PropertyChangeSupport, .

. PropertyChangeSupport, , openjdk, Apache Commons Event. , , , , , ( ) ( , ).

, Java , ; . -?

+2

, Java, , , , , , , , , , , , .

, , .

JMX.

MBeans, MBeans. MBean .

( ), , .

+1

Java, IPython , Python , Java.

0

Java , . Java , Cocoa NSNotification, Java- . 18 " Objective-C Java".

0


Java IOS NSNotificationCenter.
: Github

0

All Articles