Interpreter2.java
1    /* This program is intended to paint different color dots in a window 
2     * 
3     * The commands that interpreter1 recognizes and responds to are: 
4     * BLUE: paint blue dot 
5     * RED: paint red dot 
6     * GREEN: paint green dot 
7     * YELLOW: paint yellow dot 
8     * HELP: show a list of commands 
9     * EXIT: END PROGRAM 
10    */
11   package Interpreters;
12   import java.awt.Color;
13   import javax.swing.JOptionPane;
14   import javax.swing.SwingUtilities;
15   import painter.SPainter;
16   import shapes.SCircle;
17   public class Interpreter2 {
18       private void interpreter() {
19           SPainter marsh = new SPainter("Dots", 400, 400);
20           marsh.setScreenLocation(0, 0);
21           SCircle dot = new SCircle(180);
22           while (true) {
23               String command = JOptionPane.showInputDialog(null, "Command?");
24               if (command == null) {
25                   command = "exit";
26               } //user clicked on cancel
27               if (command.equalsIgnoreCase("blue")) {
28                   marsh.setColor(Color.BLUE);
29                   marsh.paint(dot);
30               } else if (command.equalsIgnoreCase("red")) {
31                   marsh.setColor(Color.RED);
32                   marsh.paint(dot);
33               } else if (command.equalsIgnoreCase("yellow")) {
34                   marsh.setColor(Color.YELLOW);
35                   marsh.paint(dot);
36               } else if (command.equalsIgnoreCase("green")) {
37                   marsh.setColor(Color.GREEN);
38                   marsh.paint(dot);
39               } else if (command.equalsIgnoreCase("help")) {
40                   JOptionPane.showMessageDialog(null, "Valid commands are: "
41                           + "RED | BLUE | GREEN | YELLOW | HELP | EXIT");
42               } else if (command.equalsIgnoreCase("exit")) {
43                   marsh.end();
44                   System.out.println("Thank you for the dots...");
45                   break;
46               } else {
47                   JOptionPane.showMessageDialog(null, "Command not understood please try again :P "
48                           + command.toUpperCase());
49               }
50           }
51   
52       }
53       //Painting stuff here ,-,
54       public Interpreter2() {
55           interpreter();
56       }
57       public static void main(String[] args) {
58           SwingUtilities.invokeLater(new Runnable() {
59               public void run() {
60                   new Interpreter2();
61               }
62           });
63       }
64   }