1 package interpreters; 2 import java.awt.Color; 3 import javax.swing.JOptionPane; 4 import javax.swing.SwingUtilities; 5 6 import painter.SPainter; 7 import shapes.SCircle; 8 9 public class Interpreter2 { 10 private void interpreter() { 11 //Create OBJECTS TO THINK WITH 12 SPainter miro = new SPainter("Dot string", 400, 400); 13 miro.setScreenLocation(0, 0); 14 SCircle dot = new SCircle(180); 15 // REPEATEDLY TAKE A COMMAND FROM AN INPUT DIALOG BOX AND INTERPRET IT 16 while (true) { 17 String command = JOptionPane.showInputDialog(null, "command?"); 18 if (command == null) { 19 command = "exit"; 20 }//user clicked on cancel 21 if (command.equalsIgnoreCase("blue")) { 22 miro.setColor(Color.blue); 23 miro.paint(dot); 24 } else if (command.equalsIgnoreCase("red")) { 25 miro.setColor(Color.red); 26 miro.paint(dot); 27 28 } else if (command.equalsIgnoreCase("Green")) { 29 miro.setColor(Color.GREEN); 30 miro.paint(dot); 31 } else if (command.equalsIgnoreCase("Yellow")){ 32 miro.setColor(Color.yellow); 33 miro.paint(dot); 34 35 } else if (command.equalsIgnoreCase("help")) { 36 JOptionPane.showMessageDialog(null, "valid commands are:" 37 + "Red| BLUE |Green|YELLOW | HELP |EXIT"); 38 39 } else if (command.equalsIgnoreCase("exit")) { 40 miro.end(); 41 System.out.println(" Thank you for viewing the dots..."); 42 break; 43 } else { 44 JOptionPane.showMessageDialog(null, "Unrecognizable command:" + command.toUpperCase()); 45 } 46 //INFRASTRUCTURE FOR SOME SIMPLE PAINTING 47 48 49 } 50 } 51 52 53 54 public Interpreter2() { 55 interpreter(); 56 } 57 58 public static void main(String[] args) { 59 SwingUtilities.invokeLater(new Runnable() { 60 public void run() { 61 new Interpreter2(); 62 } 63 }); 64 65 } 66 } 67