// GameButton.java Copyright (c) 2004 brising.com import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import javax.swing.JButton; /** I am a button that doesn't do anything. I serve two purposes: 1) I sit in the corners of the game button matrix and take up space, and 2) I am a superclass for the other two kinds of buttons in the game. */ public class GameButton extends JButton implements ActionListener { // STATIC VARIABLES /////////////////////////////////////////////////////////// static public final String gksUpdateScore = "updateScore"; static protected final PropertyChangeSupport gkoPropertyChangeSupport = new PropertyChangeSupport(GameButton.class); // PUBLIC STATIC METHODS ////////////////////////////////////////////////////// static public void addScoreListener ( PropertyChangeListener aoPropertyChangeListener ) { gkoPropertyChangeSupport.addPropertyChangeListener (aoPropertyChangeListener); } static public void removeScoreListener (PropertyChangeListener aoPropertyChangeListener) { gkoPropertyChangeSupport.removePropertyChangeListener (aoPropertyChangeListener); } // CONSTRUCTORS /////////////////////////////////////////////////////////////// public GameButton() { addActionListener(this); reset(); } // PUBLIC INSTANCE METHODS //////////////////////////////////////////////////// /** I do nothing when pressed. */ public void actionPerformed ( ActionEvent ae ) { // do nothing } /** My default background color is white. */ public Color getBackgroundDefault ( ) { return Color.white; } /** I never affect the game's score. */ public int getScore ( ) { return 0; } /** Am I in my default state? */ public boolean hasBackgroundDefault ( ) { return getBackground().equals(getBackgroundDefault()); } /** I never fire Photons, and you goofed if this happens. */ public void initiate ( ) { throw new RuntimeException("Do not invoke initiate() on " + this); } /** I am never occupied. */ public boolean isOccupied ( ) { return false; } /** I don't propagate Photons. */ public boolean isPropagating ( ) { return false; } /** Resume my default state. */ public void reset ( ) { setBackground(getBackgroundDefault()); } /** I am never occupied, and you goofed if this happens. */ public void setOccupied ( boolean ay ) { throw new RuntimeException("Do not invoke setOccupied() on " + this); } /** I never accept Photons, and you goofed if this happens. */ public void terminate ( ) { throw new RuntimeException("Do not invoke terminate() on " + this); } // PROTECTED INSTANCE METHODS ///////////////////////////////////////////////// /** Notify my listeners that the score must change. */ protected void changeScore ( ) { gkoPropertyChangeSupport.firePropertyChange (gksUpdateScore,0,getScore()); } }