Applets
Douglas Blank, Bryn Mawr College
Review of Assignment #7
Working with Java via command-line
Java in Control
public void play() {� state = states.find(startState);� while (true) {� if (state != null) {� System.out.println(state.description);� System.out.print("Possible paths to the "); � state.connections.print();� } else {� System.out.println("State not found: " + state);� }� String command = readLine();� if (command == null) {� break;� } else {� String next_name = state.connections.find(command);� if (next_name != null)� state = states.find(next_name);� }� }� }
Java in Control
public void play() {� state = states.find(startState);� while (true) {� if (state != null) {� System.out.println(state.description);� System.out.print("Possible paths to the "); � state.connections.print();� } else {� System.out.println("State not found: " + state);� }� String command = readLine();� if (command == null) {� break;� } else {� String next_name = state.connections.find(command);� if (next_name != null)� state = states.find(next_name);� }� }� }
Web in Control
Web in Control: Event-driven Algorithm
public class TextAdventure extends Applet implements � ActionListener {�
public void init() { ...
button.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {� String text = entry.getText();� game.makeMovement(text);� description.setText("You moved '" + entry.getText() � + "'. " + game.getDescription()� + " What would you like to do next?");� entry.setText(game.getConnections());� }�}�
actionPerformed is called each time you click on button.
Handin for Assignment #7