Package akka.weather

Source Code of akka.weather.WeatherServiceUIImpl

package akka.weather;

import javax.swing.JLabel;
import javax.swing.SwingUtilities;

import akka.actor.TypedActor;
import akka.dispatch.Future;
import akka.japi.Procedure;
import akka.weather.WeatherSensor.WeatherData;

public class WeatherServiceUIImpl extends TypedActor implements WeatherServiceUI {
  private WeatherService service;
  private JLabel temperatureLabel;
  private JLabel humidityLabel;

  public WeatherServiceUIImpl(WeatherService service, JLabel temperatureLabel, JLabel humidityLabel) {
    this.service = service;
    this.temperatureLabel = temperatureLabel;
    this.humidityLabel = humidityLabel;
  }

  public void update() {
    service.get().onComplete(new Procedure<Future<WeatherData>>() {
      public void apply(Future<WeatherData> future) {
        final WeatherData data = future.result().get();
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            temperatureLabel.setText(String.valueOf(data.temperature));
            humidityLabel.setText(String.valueOf(data.humidity));
          }
        });
      }
    });
  }

}
TOP

Related Classes of akka.weather.WeatherServiceUIImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.