Interpreter3.java
1    package interpreters;
2    
3    import java.awt.Color;
4    import javax.swing.JOptionPane;
5    import javax.swing.SwingUtilities;
6    import painter.SPainter;
7    import shapes.SCircle;
8    import shapes.SSquare;
9    
10   public class Interpreter3 {
11   
12       private void interpreter() {
13   
14           SPainter miro = new SPainter("Dot Thing", 400, 400);
15           miro.setScreenLocation(0, 0);
16           SCircle dot = new SCircle(180);
17   
18           while (true) {
19               String command = JOptionPane.showInputDialog(null, "Command?");
20               if (command == null) {
21                   command = "exit";
22               }
23               if (command.equalsIgnoreCase("red")) {
24                   miro.setColor(Color.RED);
25                   miro.paint(dot);
26               } else if (command.equalsIgnoreCase("blue")) {
27                   miro.setColor(Color.BLUE);
28                   miro.paint(dot);
29               } else if (command.equalsIgnoreCase("green")) {
30                   miro.setColor(Color.GREEN);
31                   miro.paint(dot);
32               } else if (command.equalsIgnoreCase("yellow")) {
33                   miro.setColor(Color.YELLOW);
34                   miro.paint(dot);
35               } else if (command.equalsIgnoreCase("random")) {
36                   miro.setColor(randomColor());
37                   miro.paint(dot);
38               } else if (command.equalsIgnoreCase("help")) {
39                   JOptionPane.showMessageDialog(null, "Valid commands are: " + "RED | BLUE | GREEN | YELLOW | RANDOM | HELP | EXIT ");
40               } else if (command.equalsIgnoreCase("exit")) {
41                   miro.end();
42                   System.out.println("Thank you for viewing the dots ...");
43                   break;
44               } else {
45                   JOptionPane.showMessageDialog(null, "Unrecognizable command: " + command.toUpperCase());
46   
47               }
48           }
49       }
50   
51       private static Color randomColor() {
52           int rv = (int) (Math.random()*256);
53           int gv = (int) (Math.random()*256);
54           int bv = (int) (Math.random()*256);
55           return new Color(rv,gv,bv);
56       }
57   
58       public Interpreter3() {
59           interpreter();
60   
61       }
62   
63       public static void main(String[] args) {
64           SwingUtilities.invokeLater(new Runnable() {
65               public void run() {
66                   new Interpreter3();
67               }
68           });
69       }
70   }
71