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