Interpreter3.java
1    package interpreters;
2    
3    import java.awt.Color;
4    import javax.swing.JOptionPane;
5    import javax.swing.SwingUtilities;
6    
7    import painter.SPainter;
8    import shapes.SCircle;
9    
10   public class Interpreter3 {
11       private void interpreter() {
12           //Create OBJECTS TO THINK WITH
13           SPainter miro = new SPainter("Dot string", 400, 400);
14           miro.setScreenLocation(0, 0);
15           SCircle dot = new SCircle(180);
16           // REPEATEDLY TAKE A COMMAND FROM AN INPUT DIALOG BOX AND INTERPRET IT
17           while (true) {
18               String command = JOptionPane.showInputDialog(null, "command?");
19               if (command == null) {
20                   command = "exit";
21               }//user clicked on cancel
22               if (command.equalsIgnoreCase("blue")) {
23                   miro.setColor(Color.blue);
24                   miro.paint(dot);
25               } else if (command.equalsIgnoreCase("red")) {
26                   miro.setColor(Color.red);
27                   miro.paint(dot);
28   
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   
39               } else if (command.equalsIgnoreCase("help")) {
40                   JOptionPane.showMessageDialog(null, "valid commands are:"
41                           + "Red| BLUE |Green|YELLOW | Random |  HELP |EXIT");
42   
43               } else if (command.equalsIgnoreCase("exit")) {
44                   miro.end();
45                   System.out.println(" Thank you for viewing the dots...");
46                   break;
47               } else {
48                   JOptionPane.showMessageDialog(null, "Unrecognizable command:" + command.toUpperCase());
49               }
50               //INFRASTRUCTURE FOR SOME SIMPLE PAINTING
51   
52   
53           }
54       }
55   
56       private static Color randomColor() {
57           int rv = (int) (Math.random() * 256);
58           int gv = (int) (Math.random() * 256);
59           int bv = (int) (Math.random() * 256);
60           return new Color(rv, gv, bv);
61       }
62   
63   
64       public Interpreter3() {
65           interpreter();
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