another look at swing event handlers

There are 2 distinct threads that interact in very restricted ways. Note the terminology
– METHOD is a compile-time, almostJ
– OBJECT is creation/event time
– CALL is always runtime
C) Thread C CCCreates the (event handler or) listener OBJECT. Often some reference objects (in the form of final arguments) are passed to the creator CALL (not  “method”) at Setup time. Creator passes them to the new event handler OBJECT (not “call”). At Setup time (not event time), event handler OBJECT (not “method” or “call”) has a copy or reference of those reference objects. This is all set up on Thread C. If the event never happen, then the event handler method never becomes a call.
E) Thread E dispatches the EEEvent to the handler OBJECT. In the handler CALL (not “method”), those reference objects are already there, not passed in at event time, and not passed on Thread E. A reference object is like a special device pre-installed in a James Bond car, available at event time.
Note the event handler OBJECT is really a wrapper-over—function-pointer with an invisible-field-for-each-reference-object. Each reference object passed to the creator CALL is stored in the handler OBJECT as an invisible instance field.
An event handler object is stateless and immutable since it can only have invisible fields.
The reference objects hold business data and are actively shared between Thread C and Thread E. Both threads can modify state of those reference objects.
      protected StructureEditAction createOfferingStructureEditAction (final Vector updaterList) {
            // this new() runs on Thread C
            return new StructureEditAction () {
                  // at creation-time, the implicit no-arg ctor saves updaterList as an invisible field. 
                 // This field is never needed until event-time
                  // this method runs on Thread E

                  public void startEdit (KeyEvent e) {

                        Iterator iter = updaterList.iterator ();
                        while (iter.hasNext ()) {
                              Object obj = ();
                              if (((OfferingUpdate) obj).isUpdatingColumn ((JTable) e.getSource ())) {
                                    ((OfferingUpdate) obj).startEdit (e);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s