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