//package coco;
import java.awt.*;

/*simple component that will show a number and increment itself
  whenever a request comes*/
public final class CocoCounter extends Label implements CocoComponent{
  /*the number to show*/
  int count;

  /*coco id of this component*/
  String id;

  /*state string is the count converted to string*/
  public String getState(){
    return Integer.toString(count);
  }

  /*invert the above method*/
  public void setState(String s){
    count=Integer.parseInt(s);
  }
  
  /*introduce myself*/
  public String getCocoId(){
    return id;
  }
  
  /*rename me*/
  public void setCocoId(String s){
    id=s;
  }
  
  /*the only request is to increment counter*/
  public void request(String s){
    if("INC".equals(s.trim())){
      count++;
      repaint();
    }
  }

  /*that's what it looks like*/
  public void paint(Graphics g){
    /*before drawing a simple label, set its text to display the
      counter value*/
    setText(Integer.toString(count));
    super.paint(g);
  }
}
