Read the program ButtonTest.java into your text editor
Modify the program as follows:
Change the blueButton so that it's event handling is done by an anonymous inner class. The ActionListener interface will serve as the "base class" for the anonymous inner class (this is okay, even though interfaces cannot be instantiated). Within the anonymous class definition you will specify the required event-handling method, which contains a couple of lines of code to change the color.
Change the yellowButton so that an instance of a "top level" class (not an inner class) which you create, called ButtonListener, will do the event handling for it. You will need to define the class, and also create an instance of it, passing to the constructor the reference to the ButtonPanel (the "this" object). The constructor should save this reference in an instance variable. This reference is needed for a "callback" when the event is being handled. That is, the calls to setBackground() and repaint() should be done on the ButtonPanel object, not the ButtonListener object. After all, your listener object has no background - it's not even a visible object! It needs to set its creator object's background. That's why you saved the reference to the ButtonPanel in the ButtonListener's constructor.
Change the redButton so that it uses an named "inner" class to the ButtonPanel. This is very handy, since the setBackground and repaint methods can both use the implied object of "this" (the ButtonPanel). If the listener is an inner class, then it automatically has access to its enclosing class' "this". So with the inner class, there is no need to pass the ButtonPanel's reference as with the "top-level" class. Of course, you still need to create an instance of the inner class, and register it as the listener for the redButton.
Some additional hints:
Since each color button has a different listener object, each listener should know exactly what color to set. Therefore, there is no need to get the current background color, and then use if tests to decide whether or not to replace it with another color, as the textbook does. Just set the new color and repaint!
Remember that listeners must be "implementors" of the appropriate interface. They must also be "registered" as listeners by calling the appropriate method on behalf of the button object being listened to. Finally, the event-handling object must have the event notification method required by the interface. The code to change the background color must go there.
Obviously, you should modify one button's event handling at a time, and get it working before modifying the other.