The Essential JViews Framework > Getting Started with JViews Framework > Step 3 - Using Events > Listening for a Change of Interactors

In the Sample3.java file, you will notice that the class implements the interface InteractorListener. You may also have noticed that we have imported a new package, ilog.views.event, which is the package that contains the ILOG JViews event classes. The InteractorListener interface includes one method:

void interactorChanged(InteractorChangedEvent event)  

In this example, we want the selected button to be red when its corresponding interactor is attached to the view.

The interactorChanged method will be called when the interactor changes on the view (as soon as the object, the instance of Sample3, is registered as a listener; see Registering the Listener). The parameter is an event that contains the old and the new interactor. We simply change the background color of the button corresponding to the newly installed interactor to red:

public void interactorChanged(InteractorChangedEvent event)
{
     IlvManagerViewInteractor oldI = event.getOldValue();
     IlvManagerViewInteractor newI = event.getNewValue();

     if (oldI == selectInteractor)
       selectButton.setBackground(Color.gray);
     else if (oldI == zoomInteractor)
       zoomButton.setBackground(Color.gray);
     else if (oldI == unZoomInteractor)
       unZoomButton.setBackground(Color.gray);

     // there is no new interactor
     if (newI == null)
       return;
     if (newI == selectInteractor)
       selectButton.setBackground(Color.red);
     else if (newI == zoomInteractor)
       zoomButton.setBackground(Color.red);
     else if (newI == unZoomInteractor)
       unZoomButton.setBackground(Color.red);
}

Code Sample 2.2 Changing the Color of an Interactor Button