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    
8    public class Interpreter3 {
9        private void interpreter() {
10           //create objects 2 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 a dialogue box and interpret it
16           while ( true ){
17               String command = JOptionPane.showInputDialog(null, "command?");
18               if ( command == null ) { command = "exit"; } // user clicked cancel
19               if ( command.equalsIgnoreCase("blue") ) {
20                   miro.setColor(Color.BLUE);
21                   miro.paint(dot);
22               } else if ( command.equalsIgnoreCase("red") ) {
23                   miro.setColor(Color.red);
24                   miro.paint(dot);
25               } else if ( command.equalsIgnoreCase("green") ) {
26                   miro.setColor(Color.green);
27                   miro.paint(dot);
28               } else if ( command.equalsIgnoreCase("yellow") ) {
29                   miro.setColor(Color.yellow);
30                   miro.paint(dot);
31               } else if (command.equalsIgnoreCase("random") ) {
32                   miro.setColor(randomColor());
33                   miro.paint(dot);
34               }else if ( command.equalsIgnoreCase("help") ) {
35                   JOptionPane.showMessageDialog(null, "valid commands are : "
36                           + "RED | BLUE | GREEN | YELLOW | RANDOM | HELP | EXIT");
37               }else if (command.equalsIgnoreCase("exit") ) {
38                   miro.end();
39                   System.out.println("Thank you for viewing these dots . . . ");
40                   break;
41               }else {
42                   JOptionPane.showMessageDialog(null, "Unrecognizable command: "
43                           + command.toUpperCase());
44   
45   
46   
47   
48               }
49           }
50       }
51   
52       private Color randomColor() {
53           int rv = (int)(Math.random()*256);
54           int gv = (int)(Math.random()*256);
55           int bv = (int)(Math.random()*256);
56           return new Color(rv,gv,bv);
57       }
58   
59       //INFRASTRUCTURE 4 SIMPLE PAINTING
60       public Interpreter3(){
61           interpreter();
62       }
63       public static void main(String[] args) {
64           SwingUtilities.invokeLater(new Runnable() {
65               @Override
66               public void run() {
67                   new Interpreter3();
68               }
69           });
70       };
71   }