1 // Commands are BLUE: RED: GREEN: YELLOW: 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 Interperter2 { 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 40 } else if (command.equalsIgnoreCase("help")) { 41 JOptionPane.showMessageDialog(null, "Valid commands are:" + "RED | BLUE | GREEN | YELLOW | HELP | EXIT"); 42 } else if (command.equalsIgnoreCase("exit")) { 43 miro.end(); 44 System.out.println("Thank you for viewing the dots . . ."); 45 break; 46 } else { 47 JOptionPane.showMessageDialog(null, "Unrecognized Command: " + command.toUpperCase()); 48 } 49 } 50 51 } 52 public Interperter2(){ 53 interperter(); 54 } 55 56 57 public static void main(String[] args) { 58 SwingUtilities.invokeLater(new Runnable() { 59 public void run() { 60 new Interperter2(); 61 } 62 }); 63 } 64 65 66 } 67