1 /*This is the interpreter intended to paint different colored dots 2 Commands are BLUE, RED, HELP, and EXIT 3 */ 4 5 package interpreters; 6 7 import java.awt.Color; 8 import javax.swing.JOptionPane; 9 import javax.swing.SwingUtilities; 10 import painter.SPainter; 11 import shapes.SCircle; 12 13 public class Interpreter2 { 14 15 public void interpreter() { 16 //CREATE OBJECTS TO THINK WITH 17 SPainter miro = new SPainter("Dot Thing", 400, 400); 18 miro.setScreenLocation(0,0); 19 SCircle dot = new SCircle(180); 20 21 while ( true ){ 22 String command = JOptionPane.showInputDialog(null,"Command"); 23 if ( command == null ) { command = "exit"; } // user clicked on Cancel 24 if ( command.equalsIgnoreCase("blue") ) { 25 miro.setColor(Color.blue); 26 miro.paint(dot); 27 } else if ( command.equalsIgnoreCase("red") ) { 28 miro.setColor(Color.red); 29 miro.paint(dot); 30 } else if ( command.equalsIgnoreCase("green") ) { 31 miro.setColor(Color.green); 32 miro.paint(dot); 33 } else if ( command.equalsIgnoreCase("yellow") ) { 34 miro.setColor(Color.yellow); 35 miro.paint(dot); 36 } else if ( command.equalsIgnoreCase("help") ) { 37 JOptionPane.showMessageDialog(null, "Valid commands are: " + "RED | BLUE | HELP | EXIT | GREEN | YELLOW "); 38 } else if ( command.equalsIgnoreCase("exit") ) { 39 miro.end(); 40 System.out.println("Thank you for viewing the dots ..."); 41 break; 42 } else { 43 JOptionPane.showMessageDialog(null, "Unrecognizable command: " + command.toUpperCase()); 44 45 } 46 } 47 } 48 49 public Interpreter2() { 50 interpreter(); 51 } 52 53 public static void main(String[] args) { 54 SwingUtilities.invokeLater(new Runnable() { 55 public void run() { 56 new Interpreter2();} 57 }); 58 } 59 } 60