Interpreter1.java
1    package interpreters;
2    import java.awt.Color;
3    import javax.swing.JOptionPane;
4    import javax.swing.SwingUtilities;
5    import painter.SPainter;
6    import shapes.SCircle;
7    public class Interpreter1 {
8    
9        private void Interpreter()
10       {
11           //CREATE OBJECTS TO THINK WITH
12           SPainter miro=new SPainter("Dot Thing",400,400);
13           miro.setScreenLocation(0,0);
14           SCircle dot=new SCircle(180);
15           // REPEATEDLY TAKE A COMMAND FROM AN INPUT DIALOG BOX AND INTERPRET IT
16           while(true)
17           {
18               String command=JOptionPane.showInputDialog(null,"Command?");
19               if(command==null) {command="exit"; }//user clicked Cancel
20               if(command.equalsIgnoreCase("blue")){
21                   miro.setColor(Color.BLUE);
22                   miro.paint(dot);
23               }
24               else if(command.equalsIgnoreCase("red"))
25               {
26                   miro.setColor(Color.RED);
27                   miro.paint(dot);
28               }
29               else if(command.equalsIgnoreCase("help"))
30               {
31                   JOptionPane.showMessageDialog(null,"Valid commands are:"+"RED | BLUE | HELP | EXIT ");
32               }
33               else if(command.equalsIgnoreCase("exit"))
34               {
35                  miro.end();
36                  System.out.println("thank you for viewing the dots ...");
37                  break;
38               }
39               else{
40                   JOptionPane.showMessageDialog(null,"Unrecognizable command: "+ command.toUpperCase());
41               }
42           }
43       }
44   
45   
46   public Interpreter1()
47   {
48   
49       Interpreter();
50   }
51       public static void main(String[] args)
52       {
53           SwingUtilities.invokeLater(new Runnable() {
54               public void run() {
55                   new Interpreter1();
56               }
57           });
58       }
59   }
60