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 void interpreter() { 11 SPainter miro = new SPainter("Dot Thing", 400, 400); 12 miro.setScreenLocation(0, 0); 13 SCircle dot = new SCircle(180); 14 15 while (true) { 16 String command = JOptionPane.showInputDialog(null, "Command?"); 17 if (command == null) { 18 command = "exit"; 19 } 20 if (command.equalsIgnoreCase("blue")) { 21 miro.setColor(Color.BLUE); 22 miro.paint(dot); 23 } else if (command.equalsIgnoreCase("red")) { 24 miro.setColor(Color.RED); 25 miro.paint(dot); 26 } else if (command.equalsIgnoreCase("green")) { 27 miro.setColor(Color.green); 28 miro.paint(dot); 29 } else if (command.equalsIgnoreCase("yellow")) { 30 miro.setColor(Color.yellow); 31 miro.paint(dot); 32 }else if (command.equalsIgnoreCase("random")){ 33 miro.setColor(randomColor()); 34 miro.paint(dot); 35 } else if (command.equalsIgnoreCase("help")) { 36 JOptionPane.showMessageDialog(null, "Valid commands are :" + "RED | BLUE | GREEN | YELLOW | RANDOM | HELP | EXIT "); 37 } else if (command.equalsIgnoreCase("exit")) { 38 miro.end(); 39 System.out.println("Thank you for viewing the dots ...."); 40 break; 41 } else { 42 JOptionPane.showMessageDialog(null, "Unrecognizable command: " + command.toUpperCase()); 43 } 44 } 45 } 46 47 private static Color randomColor() { 48 int rv = (int)(Math.random()*256); 49 int gv = (int)(Math.random()*256); 50 int bv = (int)(Math.random()*256); 51 return new Color(rv,gv,bv); 52 } 53 54 public Interpreter3() { 55 interpreter(); 56 } 57 58 public static void main (String[] args ) { 59 SwingUtilities.invokeLater(new Runnable() { 60 public void run() { 61 new Interpreter3(); 62 } 63 }); 64 } 65 }