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 Interpreter1 { 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("help") ) { 26 JOptionPane.showMessageDialog(null, "valid commands are : " 27 + "RED | BLUE | HELP | EXIT"); 28 }else if (command.equalsIgnoreCase("exit") ) { 29 miro.end(); 30 System.out.println("Thank you for viewing these dots . . . "); 31 break; 32 }else { 33 JOptionPane.showMessageDialog(null, "Unrecognizable command: " 34 + command.toUpperCase()); 35 36 37 38 39 } 40 } 41 } 42 //INFRASTRUCTURE 4 SIMPLE PAINTING 43 public Interpreter1(){ 44 interpreter(); 45 } 46 public static void main(String[] args) { 47 SwingUtilities.invokeLater(new Runnable() { 48 @Override 49 public void run() { 50 new Interpreter1(); 51 } 52 }); 53 }; 54 }