12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package wuerfel.controller;
-
- import java.util.concurrent.Flow;
- import java.util.concurrent.Flow.Subscriber;
- import java.util.concurrent.Flow.Subscription;
- import javax.swing.JOptionPane;
- import wuerfel.model.WuerfelModel;
- import wuerfel.view.WuerfelView;
-
- /**
- *
- * @author leo
- */
- public class WertAdapter implements Subscriber<Integer>
- {
- private WuerfelView view;
- private WuerfelModel model;
- private Subscription subscription;
-
- public WertAdapter(WuerfelView view, WuerfelModel model)
- {
- this.view = view;
- this.model = model;
- }
-
- public void einschreiben()
- {
- model.addWertSubscription(this);
- }
-
- @Override
- public void onSubscribe(Flow.Subscription subscription)
- {
- this.subscription = subscription; // wird bei onNext und onError gebraucht
- subscription.request(1); // 1 Wert bekommen
- }
-
- @Override
- public void onNext(Integer item)
- {
- String strWert = String.valueOf(item); // Wert in String umwandeln
- view.getLblWert().setText(strWert);
-
- subscription.request(1); // für nächsten Wert anmelden
- }
-
- @Override
- public void onError(Throwable throwable)
- {
- JOptionPane.showMessageDialog(view, throwable.toString());
- }
-
- @Override
- public void onComplete() // Fertig
- {
-
- }
-
- }
|