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        private void Interpreter()
9        {
10           //CREATE OBJECTS TO THINK WITH
11           SPainter miro=new SPainter("Dot Thing",400,400);
12           miro.setScreenLocation(0,0);
13           SCircle dot=new SCircle(180);
14   
15           // REPEATEDLY TAKE A COMMAND FROM AN INPUT DIALOG BOX AND INTERPRET IT
16           while(true)
17           {
18               String command=JOptionPane.showInputDialog(null,"Command?");
19               if(command==null) {command="exit"; }//user clicked Cancel
20               if(command.equalsIgnoreCase("blue")){
21                   miro.setColor(Color.BLUE);
22                   miro.paint(dot);
23               }
24               else if(command.equalsIgnoreCase("red"))
25               {
26                   miro.setColor(Color.RED);
27                   miro.paint(dot);
28               }
29               else if(command.equalsIgnoreCase("green"))
30               {
31                   miro.setColor(Color.GREEN);
32                   miro.paint(dot);
33               }
34               else if(command.equalsIgnoreCase("yellow"))
35               {
36                   miro.setColor(Color.YELLOW);
37                   miro.paint(dot);
38               }
39               else if(command.equalsIgnoreCase("help"))
40               {
41                   JOptionPane.showMessageDialog(null,"Valid commands are:"+"RED | BLUE | HELP | GREEN | YELLOW | RANDOM | EXIT ");
42               }
43               else if(command.equalsIgnoreCase("random"))
44               {
45                 miro.setColor(randomColor());
46                 miro.paint(dot);
47               }
48               else if(command.equalsIgnoreCase("exit"))
49               {
50                   miro.end();
51                   System.out.println("thank you for viewing the dots ...");
52                   break;
53               }
54               else{
55                   JOptionPane.showMessageDialog(null,"Unrecognizable command: "+ command.toUpperCase());
56               }
57           }
58       }
59   
60   
61       public Interpreter3()
62       {
63   
64           Interpreter();
65       }
66       private static Color randomColor()
67       {
68           int rv=(int)(Math.random()*256);
69           int gv=(int)(Math.random()*256);
70           int bv=(int)(Math.random()*256);
71           return new Color(rv,gv,bv);
72       }
73       public static void main(String[] args)
74       {
75           SwingUtilities.invokeLater(new Runnable() {
76               public void run() {
77                   new Interpreter3();
78               }
79           });
80       }
81   }
82