1 2 /* 3 * This interpreter is intended to paint different colored dots in a window. 4 * The commands that the interpreter can recognize and respond to are: 5 * - Blue: paint a blue dot 6 * - Red: paint a red dot 7 * - Help: show a list of the commands in a dialog message box 8 * - Exit: terminate the program 9 */ 10 package interpreters; 11 12 import painter.SPainter; 13 import shapes.SCircle; 14 15 import javax.swing.*; 16 import java.awt.*; 17 18 public class Interpreter1 { 19 private void interpreter(){ 20 //Create objects to think with 21 SPainter miro = new SPainter("Dot Thing", 400 ,400); 22 miro.setScreenLocation(0,0); 23 SCircle dot = new SCircle(180); 24 //Repeatedly take a command from a input dialog vox and interpret it 25 while ( true ) { 26 String command = JOptionPane.showInputDialog(null, "Command?"); 27 if (command == null) { command = "exit"; } // user clicked cancel 28 if (command.equalsIgnoreCase("blue")) { 29 miro.setColor(Color.blue); 30 miro.paint(dot); 31 } else if (command.equalsIgnoreCase("red")) { 32 miro.setColor(Color.red); 33 miro.paint(dot); 34 } else if (command.equalsIgnoreCase("help")) { 35 JOptionPane.showMessageDialog(null, "Valid commands are: " + "Red | Blue | Help | Exit "); 36 }else if (command.equalsIgnoreCase("exit")) { 37 miro.end(); 38 System.out.println("Thank you for viewing the dots ..."); 39 break; 40 } else { 41 JOptionPane.showMessageDialog(null, "Unrecognizable command: " + command.toUpperCase()); 42 } 43 } 44 } 45 46 //Infrastructure for some simple painting 47 48 public Interpreter1(){ 49 interpreter(); 50 } 51 52 public static void main(String[] args) { 53 SwingUtilities.invokeLater(new Runnable() { 54 public void run() { 55 new Interpreter1(); 56 } 57 }); 58 } 59 } 60