Interpreter1.java
1    
2    
3    /* 
4    * This interpreter is intended to paint different colored dots in a window. 
5    * 
6    * The commands that the interpreter can recognize and respond to are: 
7    * -BLUE: paint a blue dot 
8    * -RED: paint a red dot 
9    * -HELP: show a list of the commands in a dialog message box 
10   * -EXIT: terminate the program 
11    */
12   package interpreters;
13   
14   import java.awt.Color;
15   import javax.swing.JOptionPane;
16   import javax.swing.SwingUtilities;
17   import shapes.SCircle;
18   import painter.SPainter;
19   
20   public class Interpreter1 {
21   
22   private void interpreter() {
23   
24       //CREAT OBJECTS TO THINK WITH
25   
26       SPainter miro = new SPainter("Dot thing", 400, 400);
27       miro.setScreenLocation(0, 0);
28       SCircle dot = new SCircle(180);
29       // REPEATEDLY TAKE A COMMAND FROM AN INPUT DIALOG BOX AND INTERPRET IT
30       while (true) {
31           String command = JOptionPane.showInputDialog(null, "Command?");
32           if (command == null) {
33               command = "exit";
34           } // user clicked on Cancel
35           if (command.equalsIgnoreCase("blue")) {
36   
37               miro.setColor(Color.BLUE);
38               miro.paint(dot);
39           } else if (command.equalsIgnoreCase("red")) {
40               miro.setColor(Color.RED);
41               miro.paint(dot);
42   
43           } else if (command.equalsIgnoreCase("help")) {
44               JOptionPane.showMessageDialog(null, "Valid commands are:" + "RED | BLUE| HELP | EXIT ");
45           } else if (command.equalsIgnoreCase("exit")) {
46               miro.end();
47               System.out.println("Thank you for viewing dots. . .");
48               break;
49   
50           } else {
51               JOptionPane.showMessageDialog(null, "Unrecognizable command:" + command.toUpperCase());
52   
53   
54           }
55   
56       }
57   }
58   
59   //INFRASTRUCTURE  FOR SOME SIMPLE PAINTING
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       });
73   
74   
75   
76   }
77   
78   
79   
80   }
81