Interpreter3.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 Interpreter3 {
10       private static Color randomColor(){
11           int rv = (int)(Math.random()*256);
12           int gv = (int)(Math.random()*256);
13           int bv = (int)(Math.random()*256);
14           return new Color(rv,gv,bv);
15       }
16   
17       private void interpreter() {
18           SPainter why = new SPainter("dot thingy majig", 400, 400);
19           why.setScreenLocation(0, 0);
20           SCircle d = new SCircle(180);
21           while (true) {
22               String command = JOptionPane.showInputDialog(null, "CoMmAnD");
23               if (command == null) {
24                   command = "exit";
25               }
26               if (command.equalsIgnoreCase("blue")) {
27                   why.setColor(Color.blue);
28                   why.paint(d);
29               } else if (command.equalsIgnoreCase("red")) {
30                   why.setColor(Color.red);
31                   why.paint(d);
32               }
33               else if (command.equalsIgnoreCase("help")) {
34                   JOptionPane.showMessageDialog(null, "Valid comments are Red|Blue|Green|Yellow|Random|Help|Exit");
35               }
36               else if (command.equalsIgnoreCase("green")) {
37                   why.setColor(Color.green);
38                   why.paint(d);
39               }
40               else if (command.equalsIgnoreCase("yellow")) {
41                   why.setColor(Color.yellow);
42                   why.paint(d);
43               }
44               else if (command.equalsIgnoreCase("exit")) {
45                   System.out.println("Thanks you for view le dots");
46                   why.end();
47                   break;
48               }
49               else if(command.equalsIgnoreCase("random")){
50                   why.setColor(randomColor());
51                   why.paint(d);
52               }
53               else {
54                   JOptionPane.showMessageDialog(null, "That is not a command, I would suggest trying the 'help' command" + command.toUpperCase());
55               }
56           }
57       }
58   
59       public Interpreter3() {
60           interpreter();
61       }
62   
63       public static void main(String[] args) {
64           SwingUtilities.invokeLater(new Runnable() {
65               public void run() {
66                   new Interpreter3();
67               }
68           });
69       }
70   }
71