/home/akc/NetBeansProjects/CS1/src/interpreters/Interpreter3.java |
1
2
3
4
5
6
7
8
9
10
11
12
13 package interpreters;
14
15 import java.awt.Color;
16 import javax.swing.JOptionPane;
17 import javax.swing.SwingUtilities;
18 import painter.SPainter;
19 import shapes.SCircle;
20
21
22
23 @author
24
25 public class Interpreter3 {
26
27 private void interpreter(){
28
29
30 SPainter miro = new SPainter ("Dot Thing",400,400);
31 miro.setScreenLocation(0, 0);
32 SCircle dot = new SCircle(180);
33
34
35 while (true) {
36 String command = JOptionPane.showInputDialog(null,"Command?");
37 if ( command == null ) { command = "exit"; }
38 if ( command.equalsIgnoreCase("blue") ) {
39 miro.setColor(Color.BLUE);
40 miro.paint(dot);
41 }else if (command.equalsIgnoreCase("red")){
42 miro.setColor(Color.RED);
43 miro.paint(dot);
44 }else if (command.equalsIgnoreCase("green")){
45 miro.setColor(Color.GREEN);
46 miro.paint(dot);
47 }else if (command.equalsIgnoreCase("yellow")){
48 miro.setColor(Color.YELLOW);
49 miro.paint(dot);
50 }else if (command.equalsIgnoreCase("random")){
51 miro.setColor(randomColor());
52 miro.paint(dot);
53 }else if (command.equalsIgnoreCase("help")){
54 JOptionPane.showMessageDialog(null,"Valid commands are: "
55 +"RED | BLUE | GREEN | YELLOW | RANDOM | HELP | EXIT");
56 }else if(command.equalsIgnoreCase("exit")) {
57 miro.end();
58 System.out.println("Thank you for viewing the dots ...");
59 break;
60 }else{
61 JOptionPane.showMessageDialog(null, "Unrecognizable command: "
62 +command.toUpperCase());
63 }
64 }
65 }
66
67
68
69 public Interpreter3() {
70 interpreter();
71 }
72
73 public static void main(String[] args) {
74 SwingUtilities.invokeLater(new Runnable() {
75 public void run() {
76 new Interpreter3();
77 }
78 });
79 }
80
81 private static Color randomColor() {
82 int rv = (int)(Math.random()*256);
83 int gv = (int)(Math.random()*256);
84 int bv = (int)(Math.random()*256);
85 return new Color (rv,gv,bv);
86 }
87 }
88