Interpreter3.java
1    package Interpreters;
2    
3    import java.awt.Color;
4    import javax.swing.JOptionPane;
5    import javax.swing.SwingUtilities;
6    import painter.SPainter;
7    import shapes.SCircle;
8    
9    public class Interpreter3 {
10   
11       private void interpreter() {
12   
13           SPainter miro = new SPainter("Dot",400,400);
14           miro.setScreenLocation(0,0);
15           SCircle dot = new SCircle(180);
16   
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("help") ) {
27                   JOptionPane.showMessageDialog(null,"Valid commands are: "
28                           + "RED | BLUE | Green | Yellow | Random | Help | Exit ");
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               } else if ( command.equalsIgnoreCase("exit") ) {
39                   miro.end();
40                   System.out.println("Thank you for viewing the dots ...");
41                   break;
42               } else {
43                   JOptionPane.showMessageDialog(null, "Unrecognizable command: "+ command.toUpperCase());
44               }
45           }
46       }
47   
48       private Color randomColor() {
49           int rv = (int)(Math.random()*256);
50           int gv = (int)(Math.random()*256);
51           int bv = (int)(Math.random()*256);
52           return new Color(rv,gv,bv);
53       }
54   
55   
56       public Interpreter3() {
57           interpreter();
58       }
59   
60   
61       public static void main(String[] args) {
62           SwingUtilities.invokeLater(new Runnable() {
63               public void run() {
64                   new Interpreter3();
65               }
66           });
67       }
68   }
69   
70