import java.awt.*; import java.awt.event.*; public class NobelAdvice extends java.applet.Applet implements ActionListener { TextField mQuery, mAnswer; Button bYes, bNo; int myLocation; public void init() { mQuery = new TextField(70); mQuery.setText("Would you like to read about a scientist?"); bYes = new Button("Yes"); bNo = new Button("No"); myLocation = 0; mAnswer = new TextField(70); bYes.addActionListener(this); bNo.addActionListener(this); add(mQuery); add(bYes); add(bNo); add(mAnswer); } public void actionPerformed(ActionEvent event) { Object cause = event.getSource(); if (myLocation == 0) { if (cause == bYes) { myLocation = 1; mQuery.setText("Would you like to read about Einstein?"); } if (cause == bNo) { myLocation = 2; mQuery.setText("Would you prefer a humanitarian?"); } } else if (myLocation == 1) { if (cause == bYes) { myLocation = 3; mAnswer.setText("He received the Physics Prize in 1921."); } if (cause == bNo) { myLocation = 4; mAnswer.setText("Try the Medicine Prize in 1962."); } } else if (myLocation == 2) { if (cause == bYes) { myLocation = 5; mAnswer.setText("Look up the Peace Prize in 1991."); } if (cause == bNo) { myLocation = 6; mAnswer.setText("Try the Literature Prize, 1970."); } } } }