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