Interpreter1.java
1    /* 
2     * This interpreter is intended to paint different colored dots in a window. 
3     * The commands that the interpreter can recognize and respond to are: 
4     * - Blue: paint a blue dot 
5     * - Red: paint a red dot 
6     * - HELP: show a list of the commands in a dialog message box 
7     * - EXIT: terminate the program 
8     */
9    
10   
11   package interpreters;
12   
13   import java.awt.Color;
14   import javax.swing.JOptionPane;
15   import javax.swing.SwingUtilities;
16   
17   import painter.SPainter;
18   import shapes.SCircle;
19   
20   
21   public class Interpreter1 {
22       private void interpreter() {
23           //Create OBJECTS TO THINK WITH
24           SPainter miro = new SPainter("Dot string", 400, 400);
25           miro.setScreenLocation(0, 0);
26           SCircle dot = new SCircle(180);
27           // REPEATEDLY TAKE A COMMAND FROM AN INPUT DIALOG BOX AND INTERPRET IT
28           while (true) {
29               String command = JOptionPane.showInputDialog(null, "command?");
30               if (command == null) {
31                   command = "exit";
32               }//user clicked on cancel
33               if (command.equalsIgnoreCase("blue")) {
34                   miro.setColor(Color.blue);
35                   miro.paint(dot);
36               } else if (command.equalsIgnoreCase("red")) {
37                   miro.setColor(Color.red);
38                   miro.paint(dot);
39   
40               } else if (command.equalsIgnoreCase("help")) {
41                   JOptionPane.showMessageDialog(null, "valid commands are:"
42                           + "Red| BLUE | HELP |EXIT");
43   
44               } else if (command.equalsIgnoreCase("exit")) {
45                   miro.end();
46                   System.out.println(" Thank you for viewing the dots...");
47                   break;
48               } else {
49                   JOptionPane.showMessageDialog(null, "Unrecognizable command:" + command.toUpperCase());
50               }
51               //INFRASTRUCTURE FOR SOME SIMPLE PAINTING
52   
53   
54           }
55       }
56   
57   
58       // Infrasture for some simple painting
59   
60       public Interpreter1() {
61           interpreter();
62       }
63   
64       public static void main(String[] args) {
65           SwingUtilities.invokeLater(new Runnable() {
66               public void run() {
67                   new Interpreter1();
68               }
69           });
70   
71       }
72   }