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