You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WertAdapter.java 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package wuerfel.controller;
  7. import java.util.concurrent.Flow;
  8. import java.util.concurrent.Flow.Subscriber;
  9. import java.util.concurrent.Flow.Subscription;
  10. import javax.swing.JOptionPane;
  11. import wuerfel.model.WuerfelModel;
  12. import wuerfel.view.WuerfelView;
  13. /**
  14. *
  15. * @author leo
  16. */
  17. public class WertAdapter implements Subscriber<Integer>
  18. {
  19. private WuerfelView view;
  20. private WuerfelModel model;
  21. private Subscription subscription;
  22. public WertAdapter(WuerfelView view, WuerfelModel model)
  23. {
  24. this.view = view;
  25. this.model = model;
  26. }
  27. public void einschreiben()
  28. {
  29. model.addWertSubscription(this);
  30. }
  31. @Override
  32. public void onSubscribe(Flow.Subscription subscription)
  33. {
  34. this.subscription = subscription; // wird bei onNext und onError gebraucht
  35. subscription.request(1); // 1 Wert bekommen
  36. }
  37. @Override
  38. public void onNext(Integer item)
  39. {
  40. String strWert = String.valueOf(item); // Wert in String umwandeln
  41. view.getLblWert().setText(strWert);
  42. subscription.request(1); // für nächsten Wert anmelden
  43. }
  44. @Override
  45. public void onError(Throwable throwable)
  46. {
  47. JOptionPane.showMessageDialog(view, throwable.toString());
  48. }
  49. @Override
  50. public void onComplete() // Fertig
  51. {
  52. }
  53. }