Interpreter1.java
1    /* 
2    This interpreter is intended to paint different colored dots in a 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 dialogue message box 
8    - EXIT: terminate the program 
9     */
10   package interpreters;
11   
12   import painter.SPainter;
13   import shapes.SCircle;
14   
15   import javax.swing.*;
16   import java.awt.*;
17   
18   public class Interpreter1 {
19       private void interpreter() {
20           //CREATE OBJECTS 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               } 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       }
49       //INFRASTRUCTURE FOR SOME SIMPLE PAINTING
50       public Interpreter1() {
51           interpreter();
52       }
53       public static void main(String[] args) {
54           SwingUtilities.invokeLater(new Runnable() {
55               public void run() {
56                   new Interpreter3();
57               }
58           });
59       }
60   }
61