1 package interpreters; 2 import java.awt.Color; 3 import javax.swing.JOptionPane; 4 import javax.swing.SwingUtilities; 5 import painter.SPainter; 6 import shapes.SCircle; 7 public class Interpreter2 { 8 private void Interpreter() 9 { 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 A COMMAND FROM AN INPUT DIALOG BOX AND INTERPRET IT 16 while(true) 17 { 18 String command=JOptionPane.showInputDialog(null,"Command?"); 19 if(command==null) {command="exit"; }//user clicked Cancel 20 if(command.equalsIgnoreCase("blue")){ 21 miro.setColor(Color.BLUE); 22 miro.paint(dot); 23 } 24 else if(command.equalsIgnoreCase("red")) 25 { 26 miro.setColor(Color.RED); 27 miro.paint(dot); 28 } 29 else if(command.equalsIgnoreCase("green")) 30 { 31 miro.setColor(Color.GREEN); 32 miro.paint(dot); 33 } 34 else if(command.equalsIgnoreCase("yellow")) 35 { 36 miro.setColor(Color.YELLOW); 37 miro.paint(dot); 38 } 39 else if(command.equalsIgnoreCase("help")) 40 { 41 JOptionPane.showMessageDialog(null,"Valid commands are:"+"RED | BLUE | HELP | GREEN | YELLOW | EXIT "); 42 } 43 else if(command.equalsIgnoreCase("exit")) 44 { 45 miro.end(); 46 System.out.println("thank you for viewing the dots ..."); 47 break; 48 } 49 else{ 50 JOptionPane.showMessageDialog(null,"Unrecognizable command: "+ command.toUpperCase()); 51 } 52 } 53 } 54 55 56 public Interpreter2() 57 { 58 59 Interpreter(); 60 } 61 public static void main(String[] args) 62 { 63 SwingUtilities.invokeLater(new Runnable() { 64 public void run() { 65 new Interpreter2(); 66 } 67 }); 68 } 69 } 70