import java.awt.*;
import java.awt.event.*;

/** A Label that reverses its background and
 *  foreground colors when the mouse is over it.
 *
 *  Taken from Core Web Programming from 
 *  Prentice Hall and Sun Microsystems Press,
 *  http://www.corewebprogramming.com/.
 *  &copy; 2001 Marty Hall and Larry Brown;
 *  may be freely used or adapted. 
 */
 
public class ReversibleLabel extends Label {
  public ReversibleLabel(String text,
                         Color bgColor, Color fgColor) {
    super(text);
    MouseAdapter reverser = new MouseAdapter() {
      public void mouseEntered(MouseEvent event) {
        reverseColors();
      }

      public void mouseExited(MouseEvent event) {
        reverseColors(); // or mouseEntered(event);
      }
    };
    addMouseListener(reverser);
    setText(text);
    setBackground(bgColor);
    setForeground(fgColor);
  }

  protected void reverseColors() {
    Color fg = getForeground();
    Color bg = getBackground();
    setForeground(bg);
    setBackground(fg);
  }
}