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