Interpreter2.java
1    /* 
2     *This interpreter is intended to paint different colored dots in a window. 
3     */
4    package interpreters;
5    
6    import java.awt.Color;
7    import javax.swing.JOptionPane;
8    import javax.swing.SwingUtilities;
9    import painter.SPainter;
10   import shapes.SCircle;
11   
12   public class Interpreter2 {
13   
14       private void interpreter() {
15   
16           //Create objects to thikn with
17           SPainter miro = new SPainter("Dot Thing", 400, 400);
18           miro.setScreenLocation(0, 0);
19           SCircle dot = new SCircle(180);
20   
21           //Repeatedly take a command from an input dialog box and interpret it
22   
23           while (true) {
24               String command = JOptionPane.showInputDialog(null, "Command?");
25               if (command == null) {
26                   command = "exit";
27               } // user clicked on Cancel
28               if (command.equalsIgnoreCase("blue")) {
29                   miro.setColor(Color.blue);
30                   miro.paint(dot);
31               } else if (command.equalsIgnoreCase("red")) {
32                   miro.setColor(Color.red);
33                   miro.paint(dot);
34               } else if (command.equalsIgnoreCase("green")) {
35                   miro.setColor(Color.green);
36                   miro.paint(dot);
37               } else if (command.equalsIgnoreCase("yellow")) {
38                   miro.setColor(Color.yellow);
39                   miro.paint(dot);
40               } else if (command.equalsIgnoreCase("help")) {
41                   JOptionPane.showMessageDialog(null, "Valid commands are: " + "RED | BLUE | GREEN | YELLOW | HELP | EXIT ");
42               } else if (command.equalsIgnoreCase("exit")) {
43                   miro.end();
44                   System.out.println("Thank you for viewing the dots ...");
45                   break;
46               } else {
47                   JOptionPane.showMessageDialog(null, "Unrecognizable command: " + command.toUpperCase());
48               }
49   
50   
51           }
52       }
53   
54   
55       //  INFRASTRUCTURE FOR SOME SIMPLE PAINTING
56   
57       public Interpreter2() {
58           interpreter();
59       }
60   
61       public static void main(String[] args) {
62           SwingUtilities.invokeLater(new Runnable() {
63               public void run() {
64                   new Interpreter2();
65               }
66           });
67       }
68   }
69   
70