Interpreter2.java
1    package interpreters;
2    
3    import java.awt.Color;
4    import javax.swing.SwingUtilities;
5    import javax.swing.JOptionPane;
6    import painter.SPainter;
7    import shapes.SCircle;
8    
9    public class Interpreter2 {
10   
11       private void interpreter() {
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 AND 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               }
24               else if ( command.equalsIgnoreCase("red")) {
25                   miro.setColor(Color.RED);
26                   miro.paint(dot);
27               }
28               else if ( command.equalsIgnoreCase("yellow")) {
29                   miro.setColor(Color.YELLOW);
30                   miro.paint(dot);
31               }
32               else if (command.equalsIgnoreCase("green")) {
33                   miro.setColor(Color.GREEN);
34                   miro.paint(dot);
35               }
36               else if ( command.equalsIgnoreCase("help")) {
37                   JOptionPane.showMessageDialog(null, "Valid commands are: " + "RED | BLUE | GREEN | YELLOW | HELP | EXIT ");
38               }
39               else if ( command.equalsIgnoreCase("exit")) {
40                   miro.end();
41                   System.out.println("Thank you for viewing the dots...");
42                   break;
43               }
44               else {
45                   JOptionPane.showMessageDialog(null,"Unrecognizable command: " + command.toUpperCase());
46               }
47           }
48       }
49       public Interpreter2() {
50           interpreter();
51       }
52       public static void main (String[] args) {
53           SwingUtilities.invokeLater(new Runnable() {
54               public void run() {
55                   new Interpreter2();
56               }
57           });
58       }
59   }