Interpreter1.java
1    /* 
2    *This interperter will paint different color dots 
3    * Commands the interperter can reconize 
4    * - BLUE: paint the blue dot 
5    * - Red: paint the red dot 
6    * - HELP: show alist of the commands in a dialog message box 
7    * - EXIT: terminate the program 
8     */
9    package interpreters;
10   
11   import painter.SPainter;
12   import shapes.SCircle;
13   
14   import javax.swing.*;
15   import java.awt.*;
16   
17   public class Interpreter1 {
18       private void interpreter() {
19           //CREATE OBJECTS TO THINK WITH
20   
21           SPainter miro = new SPainter("Dot Thing", 400, 400);
22           miro.setScreenLocation(0, 0);
23           SCircle dot = new SCircle(180);
24           //REPEATEDLY TAKE A COMMAND FROM AN INPUT DIALOG BOX AND INTERPRET IT
25   
26           while (true) {
27               String command = JOptionPane.showInputDialog(null, "Command?");
28               if (command == null) { command = "exit"; }//user clicked on Cancel
29               if (command.equalsIgnoreCase("blue")) {
30                   miro.setColor(Color.BLUE);
31                   miro.paint(dot);
32               } else if (command.equalsIgnoreCase("red")) {
33                   miro.setColor(Color.RED);
34                   miro.paint(dot);
35               } else if (command.equalsIgnoreCase("help")) {
36                   JOptionPane.showMessageDialog(null, "Valid commands are: "
37                           + "RED | BLUE | 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   //Infrastructure for some simple painting
49       public Interpreter1() {
50       interpreter();
51   }
52   public static void main(String[] args) {
53       SwingUtilities.invokeLater(new Runnable() {
54           @Override
55           public void run() {
56               new Interpreter1();
57       }
58       });
59   }
60   }
61   
62   
63   
64   
65   
66   
67   
68   
69   
70   
71   
72   
73   
74