/home/sjenks/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 interporeter can recognize and respond to are:
 5  * - BLUE: paint a blue dot
 6  * - RED: paint a red dot
 7  * - YELLOW: paint a yellow dot
 8  * - GREEN: paint a green dot
 9  * - HELP: show a list of the commands in a dialog message box
10  * - EXIT: terminate the program
11  */
12 package interpreters;
13 
14 import java.awt.Color;
15 import static javafx.scene.input.KeyCode.O;
16 import javax.swing.JOptionPane;
17 import javax.swing.SwingUtilities;
18 import painter.SPainter;
19 import shapes.SCircle;
20 
21 /**
22  *
23  * @author sjenks
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 TAK A COMMAND FROM AN INPUT DIALOG BOX AND TNTERPRET IT
35         while (true) {
36             String command = JOptionPane.showInputDialog(null, "Command?");
37             if (command == null) {
38                 command = "exit";
39             } //user clicked on Cancel
40             if (command.equalsIgnoreCase("blue")) {
41                 miro.setColor(Color.BLUE);
42                 miro.paint(dot);
43             } else if ( command.equalsIgnoreCase("red")) {
44                 miro.setColor(Color.RED);
45                 miro.paint(dot);
46             } else if ( command.equalsIgnoreCase("green")) {
47                 miro.setColor(Color.GREEN);
48                 miro.paint(dot);
49             } else if ( command.equalsIgnoreCase("yellow")) {
50                 miro.setColor(Color.YELLOW);
51                 miro.paint(dot);
52             } else if (command.equalsIgnoreCase("help")) {
53                 JOptionPane.showMessageDialog(null, "Valid commands are: "
54                         + "RED | BLUE | GREEN | YELLOW | HELP | EXIT ");
55             } else if (command.equalsIgnoreCase("exit")) {
56                 miro.end();
57                 System.out.println("Thank you for viewing the dots ...");
58                 break;
59             } else {
60                 JOptionPane.showMessageDialog(null, "Unrecognizable command: "
61                         + command.toUpperCase());
62             }
63         }
64     }
65 
66 //INFRASTRUCTURE FOR SOME SIMPLE PAINTING
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 }
80