Interpreter1.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 Interpreter1 {
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("help")){
28                   JOptionPane.showMessageDialog(null, "Valid commands are: " + "RED | BLUE | HELP | CANCEL");
29               } else if (command.equalsIgnoreCase("exit")){
30                   miro.end();
31                   System.out.println("Thank you for viewing the dots...");
32                   break;
33               } else {
34                   JOptionPane.showMessageDialog(null, "Unrecognizable command: " + command.toUpperCase());
35               }
36           }
37   
38       }
39   
40       //INFRASTRUCTURE FOR SOME SIMPLE PAINTING
41       public Interpreter1(){
42           interpreter();
43       }
44   
45       public static void main(String[] args){
46           SwingUtilities.invokeLater(new Runnable() {
47               public void run() {
48                   new Interpreter1();
49               }
50           });
51       }
52   }
53