Interpreter2.java
1    package interpreters;
2    
3    import java.awt.*;
4    import javax.swing.*;
5    import painter.SPainter;
6    import shapes.SCircle;
7    
8    public class Interpreter2 {
9    
10       private void interpreter(){
11   
12           //CREATE OBJECTS TO THINK WITH
13           SPainter miro = new SPainter("Dot Thing", 400, 400);
14           miro.setScreenLocation(0,0);
15           SCircle dot = new SCircle(180);
16   
17           //REPEATEDLY TAKE A COMMAND FROM AN INPUT DIALOG BOX AND INTERPRET IT
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                   miro.setColor(Color.BLUE);
23                   miro.paint(dot);
24               } else if (command.equalsIgnoreCase("red")) {
25                   miro.setColor(Color.RED);
26                   miro.paint(dot);
27               } else if (command.equalsIgnoreCase("green")){
28                   miro.setColor(Color.GREEN);
29                   miro.paint(dot);
30               } else if (command.equalsIgnoreCase("yellow")){
31                   miro.setColor(Color.YELLOW);
32                   miro.paint(dot);
33               } else if (command.equalsIgnoreCase("help")){
34                   JOptionPane.showMessageDialog(null, "Valid commands are: " + "RED | BLUE | YELLOW | GREEN | HELP | CANCEL");
35               } else if (command.equalsIgnoreCase("exit")){
36                   miro.end();
37                   System.out.println("Thank you for viewing the dots...");
38                   break;
39               } else {
40                   JOptionPane.showMessageDialog(null, "Unrecognizable command: " + command.toUpperCase());
41               }
42           }
43   
44       }
45   
46       //INFRASTRUCTURE FOR SOME SIMPLE PAINTING
47       public Interpreter2(){
48           interpreter();
49       }
50   
51       public static void main(String[] args){
52           SwingUtilities.invokeLater(new Runnable() {
53               public void run() {
54                   new Interpreter2();
55               }
56           });
57       }
58   }
59