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       private void interpreter() {
11           // CREATE OBJECTS 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 COMMAND FROM AN INPUT  DIALOG BOX AND INTERPRET IT
17           while (true) {
18               String  command = JOptionPane.showInputDialog(null, "Command?");
19               if (command == null) {command = "exist";} // user clicked cancel
20               if (command.equalsIgnoreCase("random")) {
21                   miro.setColor(randomColor());
22                   miro.paint(dot);
23               // } else if (command.equalsIgnoreCase("GREEN")) {
24                   //miro.setColor(Color.BLUE);
25                   //miro.paint(dot);
26               // } else if (command.equalsIgnoreCase("RED")) {
27                   //miro.setColor(Color.RED);
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("help")) {
36                   JOptionPane.showMessageDialog(null, "Valid Commands are: " + "|RED|BLUE|HELP|EXIT|");
37               }else if (command.equalsIgnoreCase("exit")) {
38                   miro.end();
39                   System.out.println("bye");
40                   break;
41               } else {
42                   JOptionPane.showMessageDialog(null, "Not a command"+ command.toUpperCase());
43               }
44           }
45       }
46   
47       private Color randomColor() {
48           int rv = (int)(Math.random()*256);
49           int gv = (int)(Math.random()*256);
50           int bv = (int)(Math.random()*256);
51           return new Color(rv,gv,bv);
52       }
53   
54       // INFRASTRUCTURE FOR PAINTING
55       public Interpreter3() {interpreter();}
56       public static void main(String[] args) {
57           SwingUtilities.invokeLater(new Runnable() {
58               public void run() {
59                   new Interpreter3();
60               }
61           });
62       }
63   }
64