// Program 14.4: Two Buttons import java.applet.Applet; import java.awt.Label; import java.awt.Button; import java.awt.Event; public class DoubleFortune extends Applet { String goodnews = "You will win the lottery"; String badnews = "The government will take half your money for taxes."; Label l; public void init() { l = new Label(); l.setText( "Do you want to hear the good news or the bad news?"); add(l); add (new Button("Good News")); add (new Button("Bad News")); } public boolean action(Event e, Object o) { if (e.target instanceof Button) { return handleButton((Button) e.target, (String) o); } else { return false; } } public boolean handleButton(Button b, String s) { if (s.equals("Good News")) { l.setText(goodnews); } else if (s.equals("Bad News")) { l.setText(badnews); } else { l.setText(b.getLabel()); } return true; } }