1 package interpreters; 2 3 import painter.SPainter; 4 import shapes.SCircle; 5 import javax.swing.*; 6 import java.awt.*; 7 8 public class Interpreter2 { 9 private void interpreter() { 10 // CREATE OBJECTS TO THINK WITH 11 SPainter miro = new SPainter ("dot thing",400,400); 12 miro.setScreenLocation(0,0); 13 SCircle dot = new SCircle(180); 14 15 // REPEATEDLY TAKE COMMAND FROM AN INPUT DIALOG BOX AND INTERPRET IT 16 while (true) { 17 String command = JOptionPane.showInputDialog(null, "Command?"); 18 if (command == null) {command = "exist";} // user clicked cancel 19 if (command.equalsIgnoreCase("yellow")) { 20 miro.setColor(Color.YELLOW); 21 miro.paint(dot); 22 } else if (command.equalsIgnoreCase("green")) { 23 miro.setColor(Color.GREEN); 24 miro.paint(dot); 25 }else if (command.equalsIgnoreCase("help")) { 26 JOptionPane.showMessageDialog(null, "Valid Commands are: " + "|RED|BLUE|HELP|EXIT|"); 27 }else if (command.equalsIgnoreCase("exit")) { 28 miro.end(); 29 System.out.println("bye"); 30 break; 31 } else { 32 JOptionPane.showMessageDialog(null, "Not a command"+ command.toUpperCase()); 33 } 34 } 35 } 36 // INFRASTRUCTURE FOR PAINTING 37 public Interpreter2() {interpreter();} 38 public static void main(String[] args) { 39 SwingUtilities.invokeLater(new Runnable() { 40 public void run() { 41 new Interpreter2(); 42 } 43 }); 44 } 45 } 46 47