??????Java?????
???????????? ???????[ 2015/3/30 13:21:50 ] ????????Java ??????? ???
???????????????????? Java ???????Java event notification??????????????????????????????????????Щ???塣????????????????????????£???С????????Щ????????
????Java ?????
?????????????????? Java Bean ?????????StateHolder???????????????е? int ?????? state ???????????????
????public class StateHolder {
????private int state;
????public int getState() {
????return state;
????}
????public void setState( int state ) {
????this.state = state;
????}
????}
??????????????????? Java bean ???????????????? ?????? ?????С????????????????????????????????????????????……
????// change event to broadcast
????public class StateEvent {
????public final int oldState;
????public final int newState;
????StateEvent( int oldState?? int newState ) {
????this.oldState = oldState;
????this.newState = newState;
????}
????}
????// observer interface
????public interface StateListener {
????void stateChanged( StateEvent event );
????}
????????????????????? StateHolder ?????????? StatListeners??
????public class StateHolder {
????private final Set<StateListener> listeners = new HashSet<>();
????[...]
????public void addStateListener( StateListener listener ) {
????listeners.add( listener );
????}
????public void removeStateListener( StateListener listener ) {
????listeners.remove( listener );
????}
????}
??????????????????????StateHolder#setState????????????????????б?????????????????????????????????β????仯???
????public void setState( int state ) {
????int oldState = this.state;
????this.state = state;
????if( oldState != state ) {
????broadcast( new StateEvent( oldState?? state ) );
????}
????}
????private void broadcast( StateEvent stateEvent ) {
????for( StateListener listener : listeners ) {
????listener.stateChanged( stateEvent );
????}
????}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11