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