Interpreter1.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 Interpreter1 {
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("help")) {
31                   JOptionPane.showMessageDialog(null, "Valid commands are: "
32                           + "RED | BLUE | HELP | EXIT ");
33               } else if (command.equalsIgnoreCase("exit")) {
34                   miro.end();
35                   System.out.println("Thank you for viewing the dots ...");
36                   break;
37               } else {
38                   JOptionPane.showMessageDialog(null, "Unrecognizable command: " + command.toUpperCase());
39               }
40           }
41       }
42       public Interpreter1() {
43           interpreter();
44       }
45       public static void main(String[] args) {
46           SwingUtilities.invokeLater(new Runnable() {
47               public void run() {
48                   new Interpreter1();
49               }
50           });
51       }
52   }
53   
54