java.util.Observable.addObserver()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(216)

本文整理了Java中java.util.Observable.addObserver()方法的一些代码示例,展示了Observable.addObserver()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.addObserver()方法的具体详情如下:
包路径:java.util.Observable
类名称:Observable
方法名:addObserver

Observable.addObserver介绍

[英]Adds the specified observer to the list of observers. If it is already registered, it is not added a second time.
[中]将指定的观察者添加到观察者列表中。如果已注册,则不会再次添加。

代码示例

代码示例来源:origin: stackoverflow.com

import java.util.Observable;
import java.util.Observer;

public class Heraclitus implements Observer {
 public void observe(Observable o) {
  o.addObserver(this);
 }

 @Override
 public void update(Observable o, Object arg) {
  int someVariable = ((Flux) o).getSomeVariable();
  System.out.println("All is flux!  Some variable is now " + someVariable);
 }
}

代码示例来源:origin: stackoverflow.com

model.addObserver(this);

代码示例来源:origin: stackoverflow.com

this.add(label, BorderLayout.CENTER);
this.add(genButtonPanel(), BorderLayout.SOUTH);
model.addObserver(new ModelObserver());

代码示例来源:origin: sd4324530/fastweixin

/**
 * 添加配置变化监听器
 *
 * @param handle 监听器
 */
public void addHandle(final ApiConfigChangeHandle handle) {
  super.addObserver(handle);
}

代码示例来源:origin: sd4324530/fastweixin

public void addHandle(final ApiConfigChangeHandle handle) {
  super.addObserver(handle);
}

代码示例来源:origin: geotools/geotools

/** Constructs a <code>RecyclingTileFactory</code>. */
public RecyclingTileFactory(Observable tileCache) {
  if (tileCache instanceof TileCache) this.tileCache = tileCache;
  else throw new IllegalArgumentException("Provided argument is not of type TileCache");
  tileCache.addObserver(this);
}

代码示例来源:origin: Nilhcem/FakeSMTP

/**
 * Adds this object to the SMTP logs appender observable, to intercept logs.
 * <p>
 * The goal is to be informed when the log appender will received some debug SMTP logs.<br>
 * When a log is written, the appender will notify this class which will display it in the text area.
 * </p>
 */
private void addObserverToSmtpLogAppender() {
  Logger smtpLogger = LoggerFactory.getLogger(org.subethamail.smtp.server.Session.class);
  String appenderName = Configuration.INSTANCE.get("logback.appender.name");
  @SuppressWarnings("unchecked")
  SMTPLogsAppender<ILoggingEvent> appender = (SMTPLogsAppender<ILoggingEvent>)
    ((AppenderAttachable<ILoggingEvent>) smtpLogger).getAppender(appenderName);
  if (appender == null) {
    LoggerFactory.getLogger(LogsPane.class).error("Can't find logger: {}", appenderName);
  } else {
    appender.getObservable().addObserver(this);
  }
}

代码示例来源:origin: stackoverflow.com

observables.put(notification, observable);
observable.addObserver(observer);

代码示例来源:origin: net.java.dev.glazedlists/glazedlists_java15

/**
 * Start observing the specified <code>element</code>.
 *
 * @param element the element to be observed
 * @return the listener that was installed on the <code>element</code>
 *      to be used as a parameter to {@link #uninstallListener(Object, EventListener)}
 */
public EventListener installListener(E element) {
  element.addObserver(this);
  return this;
}

代码示例来源:origin: org.geotools/gt2-coverage

/**
 * Constructs a <code>RecyclingTileFactory</code>.
 */
public RecyclingTileFactory(Observable tileCache) {
  if (tileCache instanceof TileCache)
    this.tileCache = tileCache;
  else
    throw new IllegalArgumentException(
        "Provided argument is not of type TileCache");
  tileCache.addObserver(this);
}

代码示例来源:origin: org.kill-bill.billing/killbill-platform-osgi-bundles-logger

@Override
  public Void executeWithService(final Observable service) {
    handlerToObserver.put(handler, observer);
    service.addObserver(observer);
    return null;
  }
});

代码示例来源:origin: org.geotools/gt-coverage

/**
 * Constructs a <code>RecyclingTileFactory</code>.
 */
public RecyclingTileFactory(Observable tileCache) {
  if (tileCache instanceof TileCache)
    this.tileCache = tileCache;
  else
    throw new IllegalArgumentException(
        "Provided argument is not of type TileCache");
  tileCache.addObserver(this);
}

代码示例来源:origin: Nilhcem/FakeSMTP

menu.addObserver(dirChooser);
saveMsgTextField.addObserver(dirChooser);

代码示例来源:origin: stackoverflow.com

private Observable observable = new Observable();

public void addObserver(Observer o) {
  observable.addObserver(o);
}

public void notifyObservers() {
  observable.notifyObservers();
}

代码示例来源:origin: BruceEckel/OnJava8-Examples

OCBox(int x, int y, Observable notifier) {
 this.x = x;
 this.y = y;
 notifier.addObserver(this);
 this.notifier = notifier;
 addMouseListener((MouseClick)
  e -> notifier.notifyObservers(OCBox.this));
}
@Override

代码示例来源:origin: stackoverflow.com

import java.util.Observable;
  public class Achievement extends Observable {
  public static class AchievementDetails {}
public Achievement() {
    addObserver(EventsListener.getInstance());
  }
  public void achievementReached() {
    AchievementDetails achievemetDetails = null;
    setChanged();
    notifyObservers(achievemetDetails);
  }
}

代码示例来源:origin: org.fudaa.framework.ebli/ebli-2d

public CalqueFindCourbeTreeModel(final BArbreCalqueModel _model, final BGroupeCalque _root) {
 super();
 rootLayer_ = _root;
 if (_model != null) {
  _model.getObservable().addObserver(this);
 }
 rootNode_ = new LayerNode(rootLayer_);
 treeModel_ = new DefaultTreeModel(rootNode_);
 buildTree();
}

代码示例来源:origin: org.onap.ccsdk.sli.core/dblib-provider

@Override
public void addObserver(Observer observer) {
  if (observer instanceof DBResourceObserver) {
    DBResourceObserver dbObserver = (DBResourceObserver) observer;
    if (dbObserver.isMonitorDbResponse() && countObservers() == 0) {
      TimerTask remindTask = new MonitoringTask();
      timer.schedule(remindTask, initialDelay, interval);
      activeState = true;
    }
  }
  super.addObserver(observer);
}

代码示例来源:origin: org.fujion/fujion-core

@Override
public void setModel(M model) {
  if (this.model instanceof Observable) {
    ((Observable) this.model).deleteObserver(this);
  }
  this.model = model;
  modelChanged(null);
  targetChanged(null);
  if (this.model instanceof Observable) {
    ((Observable) this.model).addObserver(this);
  }
}

代码示例来源:origin: org.fudaa.framework.ebli/ebli-2d

/** 
 * Cration du modele a partir de la racine des calques.
 */
public CalqueGISTreeModel(final BArbreCalqueModel _model, final BGroupeCalque _root) {
 super(new LayerNode(_root));
 rootNode_=(LayerNode)getRoot();
 rootLayer_ = _root;
 if (_model != null) {
  _model.getObservable().addObserver(this);
 }
 buildTree();
}

相关文章