Interpreter2.java
1    package interpreters;
2    
3    import java.awt.Color;
4    import javax.swing.JOptionPane;
5    import javax.swing.SwingUtilities;
6    import painter.SPainter;
7    import shapes.SCircle;
8    
9    public class Interpreter2 {
10       private void interpreter() {
11   // CREATE OBJECTS TO THINK WITH
12           SPainter miro = new SPainter("Dot Thing",400,400);
13           miro.setScreenLocation(0,0);
14           SCircle dot = new SCircle(180);
15   // REPEATEDLY TAKE A COMMAND FROM AN INPUT DIALOG BOX AND INTERPRET IT
16           while ( true ) {
17               String command = JOptionPane.showInputDialog(null, "Command?");
18               if (command == null) {
19                   command = "exit";
20               } // user clicked on Cancel
21               if (command.equalsIgnoreCase("blue")) {
22                   miro.setColor(Color.BLUE);
23                   miro.paint(dot);
24               } else if (command.equalsIgnoreCase("red")) {
25                   miro.setColor(Color.RED);
26                   miro.paint(dot);
27               } else if (command.equalsIgnoreCase("green")) {
28                   miro.setColor(Color.GREEN);
29                   miro.paint(dot);
30               }else if (command.equalsIgnoreCase("yellow")) {
31                   miro.setColor(Color.YELLOW);
32                   miro.paint(dot);
33               }else if (command.equalsIgnoreCase("help")) {
34                   JOptionPane.showMessageDialog(null, "Valid commands are: "
35                           + "RED | BLUE | GREEN | YELLOW | HELP | EXIT ");
36               } else if (command.equalsIgnoreCase("exit")) {
37                   miro.end();
38                   System.out.println("Thank you for viewing the dots ...");
39                   break;
40               } else {
41                   JOptionPane.showMessageDialog(null, "Unrecognizable command: " + command.toUpperCase());
42               }
43           }
44       }
45       public Interpreter2() {
46           interpreter();
47       }
48       public static void main(String[] args) {
49           SwingUtilities.invokeLater(new Runnable() {
50               public void run() {
51                   new Interpreter2();
52               }
53           });
54       }
55   }
56