Interpreter2.java
1    package interpreters;
2    
3    import java.awt.Color;
4    import javax.swing.SwingUtilities;
5    import painter.SPainter;
6    import shapes.SCircle;
7    import javax.swing.JOptionPane;
8    
9    public class Interpreter2 {
10       private void interpreter() {
11   
12           //Create objects to think with
13           SPainter miro = new SPainter("Dot Thing", 400, 400);
14           miro.setScreenLocation(0,0);
15           SCircle dot = new SCircle(180);
16   
17           //Repeatedly take a command from an input dialog pox and interpret it
18           while (true) {
19               String command = JOptionPane.showInputDialog(null,"Command?");
20               if ( command == null) { command = "exit" ;} // 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               }
34   
35               else if ( command.equalsIgnoreCase("help")) {
36                   JOptionPane.showMessageDialog(null, "Valid commands are:" +
37                           " RED / BLUE / GREEN / YELLOW / HELP / EXIT");
38               } else if (command.equalsIgnoreCase("exit")) {
39                   miro.end();
40                   System.out.println("Thank you for viewing the dots ...");
41                   break;
42               } else {
43                   JOptionPane.showMessageDialog(null, "Unrecognizable command:" +
44                           command.toUpperCase());
45   
46               }
47           }
48   
49       }
50   
51       //Infrastructure for some simple painting
52   
53       public Interpreter2() {
54           interpreter();
55       }
56   
57       public static void main(String[] args) {
58           SwingUtilities.invokeLater(new Runnable() {
59               @Override
60               public void run() {
61                   new Interpreter2();
62               }
63           });
64       }
65   
66   
67   }
68