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 8 public class Interpreter2 { 9 private void interpreter() { 10 //create objects 2 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 a dialogue box and interpret it 16 while ( true ){ 17 String command = JOptionPane.showInputDialog(null, "command?"); 18 if ( command == null ) { command = "exit"; } // user clicked cancel 19 if ( command.equalsIgnoreCase("blue") ) { 20 miro.setColor(Color.BLUE); 21 miro.paint(dot); 22 } else if ( command.equalsIgnoreCase("red") ) { 23 miro.setColor(Color.red); 24 miro.paint(dot); 25 } else if ( command.equalsIgnoreCase("green") ) { 26 miro.setColor(Color.green); 27 miro.paint(dot); 28 } else if ( command.equalsIgnoreCase("yellow") ){ 29 miro.setColor(Color.yellow); 30 miro.paint(dot); 31 }else if ( command.equalsIgnoreCase("help") ) { 32 JOptionPane.showMessageDialog(null, "valid commands are : " 33 + "RED | BLUE | GREEN | YELLOW | HELP | EXIT"); 34 }else if (command.equalsIgnoreCase("exit") ) { 35 miro.end(); 36 System.out.println("Thank you for viewing these dots . . . "); 37 break; 38 }else { 39 JOptionPane.showMessageDialog(null, "Unrecognizable command: " 40 + command.toUpperCase()); 41 42 43 44 45 } 46 } 47 } 48 //INFRASTRUCTURE 4 SIMPLE PAINTING 49 public Interpreter2(){ 50 interpreter(); 51 } 52 public static void main(String[] args) { 53 SwingUtilities.invokeLater(new Runnable() { 54 @Override 55 public void run() { 56 new Interpreter2(); 57 } 58 }); 59 }; 60 }