Interpreter1.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 Interpreter1 {
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 IMPUT 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("help")) {
29                   JOptionPane.showMessageDialog(null, "Valid commands are: " + "RED | BLUE | HELP | EXIT ");
30               }
31               else if ( command.equalsIgnoreCase("exit")) {
32                   miro.end();
33                   System.out.println("Thank you for viewing the dots...");
34                   break;
35               }
36               else {
37                   JOptionPane.showMessageDialog(null,"Unrecognizable command: " + command.toUpperCase());
38               }
39           }
40       }
41       public Interpreter1() {
42           interpreter();
43       }
44       public static void main (String[] args) {
45           SwingUtilities.invokeLater(new Runnable() {
46               public void run() {
47                   new Interpreter1();
48               }
49           });
50       }
51   }