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