// Program 14.3: The Fortune Teller Applet
import java.applet.Applet;    
import java.awt.Label;
import java.awt.Button;
import java.awt.Event;

public class Fortune extends Applet {

  String fortune1 ="You will be happy";
  String fortune2 ="You will be wealthy";
  String fortune3 = "You will have long life.";
  Label l;
  Button b;
  private int i = 1;

  public void init() {
    l = new Label();
    l.setText("Your Fortune for a nickel");
    add(l);
    Button b = new Button("A Nickel");
    add(b);
  }
  
  public boolean action(Event e, Object o) {
    if (e.target instanceof Button) changeFortune();
  
    return true;
  }

  public void changeFortune() {
    if (i == 1) {
      l.setText(fortune1);
      i++;
    }
    else if (i == 2) {
      l.setText(fortune2);
      i++;
  }
  
    else  {
      l.setText(fortune3);
      i = 1;
   }
  
  }

}
