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