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