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