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 Interpreter3 { 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("random") ) { 37 miro.setColor(randomColor()); 38 miro.paint(dot); 39 } else if ( command.equalsIgnoreCase("help") ) { 40 JOptionPane.showMessageDialog(null, "Valid commands are: " + "RED | BLUE | HELP | EXIT | GREEN | YELLOW | RANDOM"); 41 } else if ( command.equalsIgnoreCase("exit") ) { 42 miro.end(); 43 System.out.println("Thank you for viewing the dots ..."); 44 break; 45 } else { 46 JOptionPane.showMessageDialog(null, "Unrecognizable command: " + command.toUpperCase()); 47 48 } 49 } 50 } 51 52 private static Color randomColor() { 53 int rv = (int)(Math.random()*256); 54 int gv = (int)(Math.random()*256); 55 int bv = (int)(Math.random()*256); 56 return new Color(rv, gv, bv); 57 } 58 59 public Interpreter3() { 60 interpreter(); 61 } 62 63 public static void main(String[] args) { 64 SwingUtilities.invokeLater(new Runnable() { 65 public void run() { 66 new Interpreter3();} 67 }); 68 } 69 }