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