0

I've two separate class, ClassA and ClassB and there are everything private within either of these classes, now when we dispatch any event in ClassB then ClassA should know that some event has been triggered in ClassB. i.e.:

ClassA {
    ClassB b = new ClassB();   
}

ClassB {
    JButton btn = new JButton();
    btn.onClick();
}

Now as you can see that the onClick method has been called in ClassB, then it should be known by ClassA as well. Any help would be appreciated. Thanks in advance.

diiN__________
  • 7,393
  • 6
  • 42
  • 69
Youthoria
  • 51
  • 4
  • 4
    try to use Observer pattern https://en.wikipedia.org/wiki/Observer_pattern – Sanka Aug 29 '16 at 07:16
  • 1
    Several common approaches are examined [here](http://stackoverflow.com/a/3072979/230513). – trashgod Aug 29 '16 at 09:12
  • Read up on the [`java.util.Observable`](http://docs.oracle.com/javase/8/docs/api/java/util/Observable.html) class and the [`java.util.Observer`](http://docs.oracle.com/javase/8/docs/api/java/util/Observer.html) interface that goes with it. They've been the standard way for object of one type (or more) to be informed of (to "observe") changes in another since Java 1.0. – Kevin J. Chase Aug 29 '16 at 09:27
  • Related: "[Observer/Observable in a GUI](https://stackoverflow.com/questions/28133529/)". – Kevin J. Chase Aug 29 '16 at 09:30

0 Answers0