Interpreter3.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   public class Interpreter3 {
12       private void interpreter() {
13           //Create objects to think with
14           SPainter miro = new SPainter("Dot Thing", 400, 400);
15           miro.setScreenLocation(0,0);
16           SCircle dot = new SCircle(180);
17   
18           //Repeatedly take a command from an input dialog box and interpret it
19           while (true){
20               String command = JOptionPane.showInputDialog(null, "Command?");
21               if(command == null){command = "exit";} //user clicked on cancel
22               if(command.equalsIgnoreCase("blue")){
23                   miro.setColor(Color.BLUE);
24                   miro.paint(dot);
25               }
26               else if(command.equalsIgnoreCase("red")){
27                   miro.setColor(Color.RED);
28                   miro.paint(dot);
29               }
30               else if(command.equalsIgnoreCase("green")){
31                   miro.setColor(Color.GREEN);
32                   miro.paint(dot);
33               }
34               else if(command.equalsIgnoreCase("yellow")){
35                   miro.setColor(Color.YELLOW);
36                   miro.paint(dot);
37               }
38               else if(command.equalsIgnoreCase("random")){
39                   miro.setColor(randomColor());
40                   miro.paint(dot);
41               }
42               else if(command.equalsIgnoreCase("help")){
43                   JOptionPane.showMessageDialog(null, "Valid commands are: " + "RED | BLUE | GREEN | YELLOW | RANDOM | HELP | EXIT ");
44               }
45               else if(command.equalsIgnoreCase("exit")){
46                   miro.end();
47                   System.out.println("Thank you for viewing the dots...");
48                   break;
49               }
50               else {
51                   JOptionPane.showMessageDialog(null, "Unrecognizable command: ");
52               }
53           }
54       }
55   
56       //Simple painting
57       public Interpreter3(){
58           interpreter();
59       }
60   
61       private static Color randomColor(){
62           int rv = (int)(Math.random()*256);
63           int gv = (int)(Math.random()*256);
64           int bv = (int)(Math.random()*256);
65           return new Color(rv,gv,bv);
66       }
67   
68       public static void main(String[] args){
69           SwingUtilities.invokeLater(new Runnable(){
70               public void run(){
71                   new Interpreter3();
72               }
73           });
74   
75   
76       }
77   }
78   
79       
80   
81   
82   
83