Interpreter2.java
1    /* 
2    this interpreter is intended to paint different colored dots in a window 
3     
4    commands 
5        BLUE: paint a blue dot 
6        RED:Paint a red dot 
7        Yellow 
8        Green 
9        HELP: show a list of commands 
10       EXIT: terminate program 
11    */
12   
13   package interpreters;
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   public class Interpreter2 {
21       private void interpreter() {
22           // Create objects to think with
23           SPainter miro = new SPainter("Dot Thing",400,400);
24           miro.setScreenLocation(0,0);
25           SCircle dot = new SCircle(180);
26   
27           //repetedly take a command form an input box and interpret it
28           while (true) {
29               String command = JOptionPane.showInputDialog(null,"Command");
30               if ( command == null) { command = "exit"; } //user clicked on cancel
31               if ( command.equalsIgnoreCase("blue")){
32                   miro.setColor(Color.BLUE);
33                   miro.paint(dot);
34               } else if ( command.equalsIgnoreCase("red")){
35                   miro.setColor(Color.red);
36                   miro.paint(dot);
37               } else if ( command.equalsIgnoreCase("Yellow")){
38                   miro.setColor(Color.yellow);
39                   miro.paint(dot);
40               }else if ( command.equalsIgnoreCase("Green")){
41                   miro.setColor(Color.green);
42                   miro.paint(dot);
43               } else if (command.equalsIgnoreCase("help")) {
44                   JOptionPane.showMessageDialog(null,"valid commands are:"
45                           + "RED | BLUE | HELP | EXIT | YELLOW | GREEN ");
46               } else if (command.equalsIgnoreCase("exit")) {
47                   miro.end();
48                   System.out.println("Thank you for viewing the dots");
49                   break;
50               } else {
51                   JOptionPane.showMessageDialog(null, "Unrecognizable command: "
52                           + command.toUpperCase());
53               }
54   
55           }
56       }
57   
58       // infrastructure
59       public Interpreter2(){
60           interpreter();
61       }
62       public static void main(String[] args){
63           SwingUtilities.invokeLater(new Runnable(){
64               public void run(){
65                   new Interpreter2();
66               }
67           });
68       }
69   }
70