import java.applet.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


/** MyButton class defines a smart button which can change 
 * its state automatically and wakes up corresponding methods 
 * in the playground.
 */
class MyButton extends Button implements ActionListener
{
  private BattleShip playGround;
  private int x,y;  // to tell the playGroud which button this is

  /** MyButton constructor */
  public MyButton(BattleShip b, int xcoord, int ycoord) {
    super();
    addActionListener(this);
    playGround = b;
    x = xcoord;
    y = ycoord;
  }

  /** If this button is unused, play the game, otherwise beep */
  public void actionPerformed(ActionEvent e) {
    if (getLabel() == "") {
      setLabel(playGround.Bom(x,y));
    } else {
      Toolkit.getDefaultToolkit().beep();
    }   
  }
}
