Interpreter1.java
1    package interpreters;
2    
3    /* 
4    Blue - paint a dot 
5    Red - paint a red dot 
6    help - show a list of commands in a dialog message box 
7    Exit - Terminate the program 
8     */
9    
10   import java.awt.Color;
11   import javax.swing.SwingUtilities;
12   import javax.swing.JOptionPane;
13   import painter.SPainter;
14   import shapes.SCircle;
15   
16   
17   public class Interpreter1 {
18       private void interpreter() {
19           //Create Obkjects to think with
20           SPainter miro = new SPainter("Dot thing", 400, 400);
21           miro.setScreenLocation(0,0);
22           SCircle dot = new SCircle(180);
23   
24           //Repeatedly take a command from an input dialog and Interpret it
25           while (true) {
26               String command = JOptionPane.showInputDialog(null, "Command");
27               if ( command == null) {command = "exit";} //user clicked on cancel
28               if (command.equalsIgnoreCase("blue"))
29               {
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: " + "RED | BLUE | HELP| EXIT");
37               } else if (command.equalsIgnoreCase("exit")) {
38                   miro.end();
39                   System.out.println("Thank you for viewing the dots");
40                   break;
41               } else {
42                   JOptionPane.showMessageDialog(null, "Unrecognizable command: " + command.toUpperCase());
43               }
44   
45           }
46       }
47       // Infrastructure fpr Some Simple Painting
48       public Interpreter1 () {
49           interpreter();
50       }
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