/home/kchan2/NetBeansProjects/CS1/src/interpreters/Interpreter2.java
 1 /*
 2  * This interpreter is intended to paint different colored dots in a window.
 3  * 
 4  * The commands that the interpreter can recognize and respond to are:
 5  * - BLUE: [aint a blue dot
 6  * - RED: paint a red dot
 7  * - GREEN: paint a green dot
 8  * - YELLOW: paint a yellow dot
 9  * - HELP: show a list of thst commands in a dialog message box
10  * - EXIT: terminate the program
11  */
12 
13 package interpreters;
14 
15 import java.awt.Color;
16 import javax.swing.JOptionPane;
17 import javax.swing.SwingUtilities;
18 import painter.SPainter;
19 import shapes.SCircle;
20 
21 /**
22  *
23  * @author kchan2
24  */
25 public class Interpreter2 {
26     
27     private void interpreter() {
28         
29         //CREATE OBJECTS TO THINK WITH
30         SPainter miro = new SPainter("Dot Thing",400,400);
31         miro.setScreenLocation(0,0);
32         SCircle dot = new SCircle(180);
33         
34         //REPEATEDLY TAKE A COMMAND FROM AN INPUT DIALOG BOX AND INTERPRET IT
35         while ( true ) {
36             String command = JOptionPane.showInputDialog(null,"Command?");
37             if (command == null) {command = "exit";} // user clicked on Cancel
38             if (command.equalsIgnoreCase("blue")) {
39                 miro.setColor(Color.BLUE);
40                 miro.paint(dot);
41             } else if (command.equalsIgnoreCase("red")) {
42                 miro.setColor(Color.RED);
43                 miro.paint(dot);
44             } else if (command.equalsIgnoreCase("green")) {
45                 miro.setColor(Color.green);
46                 miro.paint(dot);
47             } else if (command.equalsIgnoreCase("yellow")) {
48                 miro.setColor(Color.yellow);
49                 miro.paint(dot);
50             } else if (command.equalsIgnoreCase("help")) {
51                 JOptionPane.showMessageDialog(null,"Valid commands are: " 
52                         + "RED | BLUE | GREEN | YELLOW | HELP | EXIT");
53             } else if (command.equalsIgnoreCase("exit")) {
54                 miro.end();
55                 System.out.println("Thank you for viewing the dots ...");
56                 break;
57             } else {
58                 JOptionPane.showMessageDialog(null, "Unrecognizble command:" 
59                         + command.toUpperCase());
60             }
61             
62         }
63     }
64 
65     // INFRASTRUCTURE FOR SOME SIMPLE PAINTING
66     
67     public Interpreter2() {
68         interpreter();
69     }
70     
71     public static void main(String[] args) {
72         SwingUtilities.invokeLater(new Runnable() {
73             public void run() {
74                 new Interpreter2();
75             }
76         });
77     }
78     
79 }