Interpreter1.java
1    package interpreters;
2    
3    /* 
4    This interpreter is intended to paint different colored dots in a window; 
5    The commands that the interpreter can recognize and respond to are: 
6     
7        -blue: paint a blue dot 
8        -red : paint a red dot 
9        -HELP: s'how a list of the commands in a dialog message box 
10       -EXIT: terminate the program 
11    
12    */
13   
14   import java.awt.Color;
15   import javax.swing.JOptionPane;
16   import javax.swing.SwingUtilities;
17   import painter.SPainter;
18   import shapes.SCircle;
19   
20   
21   public class Interpreter1 {
22   
23       //Createe objects to think with
24       private void interpreter() {
25   
26           SPainter miro = new SPainter("Dot Thing", 400, 400);
27           miro.setScreenLocation(0, 0);
28           SCircle dot = new SCircle(180);
29   
30           //Repeatedly take a command from an input dialog box and interpret it
31   
32           while (true) {
33               String command = JOptionPane.showInputDialog(null, "Command?");
34               if (command == null) {command = "exit"; } //user clicked on Cancel
35   
36               if (command.equalsIgnoreCase("blue")) {
37                   miro.setColor(Color.BLUE);
38                   miro.paint(dot);
39               }
40               else if (command.equalsIgnoreCase("red")) {
41                   miro.setColor(Color.RED);
42                   miro.paint(dot);
43               }
44               else if (command.equalsIgnoreCase("help")) {
45                   JOptionPane.showMessageDialog(null, "Valid commands are: " + "RED | BLUE | HELP | EXIT");
46               }
47               else if (command.equalsIgnoreCase("exit")) {
48                   miro.end();
49                   System.out.println("Thank you for viewing the dots....");
50                   break;
51               }
52               else {
53                   JOptionPane.showMessageDialog(null, "Unrecognizable command: " + command.toUpperCase());
54               }
55           }
56       }
57   
58       public Interpreter1() { interpreter(); };
59   
60       public static void main(String[] args) {
61           SwingUtilities.invokeLater(new Runnable() {
62               @Override
63               public void run() {
64                   new Interpreter1();
65               }
66           });
67       }
68   
69   }
70