Interpreter3.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     * RANDOM: gives random color dot 
10    * EXIT: END PROGRAM 
11    */
12   package Interpreters;
13   import java.awt.Color;
14   import javax.swing.JOptionPane;
15   import javax.swing.SwingUtilities;
16   import painter.SPainter;
17   import shapes.SCircle;
18   public class Interpreter3 {
19       private void interpreter() {
20           SPainter marsh = new SPainter("Dots", 400, 400);
21           marsh.setScreenLocation(0, 0);
22           SCircle dot = new SCircle(180);
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                   marsh.setColor(Color.BLUE);
30                   marsh.paint(dot);
31               } else if (command.equalsIgnoreCase("red")) {
32                   marsh.setColor(Color.RED);
33                   marsh.paint(dot);
34               } else if (command.equalsIgnoreCase("yellow")) {
35                   marsh.setColor(Color.YELLOW);
36                   marsh.paint(dot);
37               } else if (command.equalsIgnoreCase("green")) {
38                   marsh.setColor(Color.GREEN);
39                   marsh.paint(dot);
40               } else if (command.equalsIgnoreCase("help")) {
41                   JOptionPane.showMessageDialog(null, "Valid commands are: "
42                           + "RED | BLUE | GREEN | YELLOW | HELP | RANDOM | EXIT");
43               } else if (command.equalsIgnoreCase("random")) {
44                   marsh.setColor(randomColor());
45                   marsh.paint(dot);
46               } else if (command.equalsIgnoreCase("exit")) {
47                   marsh.end();
48                   System.out.println("Thank you for the dots...");
49                   break;
50               } else {
51                   JOptionPane.showMessageDialog(null, "Command not understood please try again :P "
52                           + command.toUpperCase());
53               }
54           }
55   
56       }
57   
58       private static Color randomColor() {
59           int rv = (int) (Math.random()*256);
60           int gv =(int) (Math.random()*256);
61           int bv = (int) (Math.random()*256);
62           return new Color(rv,gv,bv);
63       }
64   
65       //Painting stuff here ,-,
66       public Interpreter3() {
67           interpreter();
68       }
69       public static void main(String[] args) {
70           SwingUtilities.invokeLater(new Runnable() {
71               public void run() {
72                   new Interpreter3();
73               }
74           });
75       }
76   }