1 package interpreters; 2 3 /* 4 Blue - paint a dot 5 Red - paint a red dot 6 Yellow - Paint a yellow dot 7 Green - paint a green dot 8 help - show a list of commands in a dialog message box 9 Exit - Terminate the program 10 */ 11 12 import java.awt.Color; 13 import javax.swing.SwingUtilities; 14 import javax.swing.JOptionPane; 15 import painter.SPainter; 16 import shapes.SCircle; 17 18 19 public class Interpreter2 { 20 private void interpreter() { 21 //Create Obkjects to think with 22 SPainter miro = new SPainter("Dot thing", 400, 400); 23 miro.setScreenLocation(0,0); 24 SCircle dot = new SCircle(180); 25 26 //Repeatedly take a command from an input dialog and Interpret it 27 while (true) { 28 String command = JOptionPane.showInputDialog(null, "Command"); 29 if ( command == null) {command = "exit";} //user clicked on cancel 30 if (command.equalsIgnoreCase("blue")) 31 { 32 miro.setColor(Color.blue); 33 miro.paint(dot); 34 } else if (command.equalsIgnoreCase("red")) { 35 miro.setColor(Color.red); 36 miro.paint(dot); 37 } else if (command.equalsIgnoreCase("green")) { //added after Int 1 38 miro.setColor(Color.green); 39 miro.paint(dot); 40 } else if (command.equalsIgnoreCase("yellow")) { //added after Int 1 41 miro.setColor(Color.yellow); 42 miro.paint(dot); 43 } else if (command.equalsIgnoreCase("help")) { 44 JOptionPane.showMessageDialog(null,"Valid Commands are: " + "RED | BLUE | YELLOW |" + 45 " GREEN | HELP| EXIT"); 46 } else if (command.equalsIgnoreCase("exit")) { 47 miro.end(); 48 System.out.println("Thank you for viewing the dots"); 49 50 break; 51 } else { 52 JOptionPane.showMessageDialog(null, "Unrecognizable command: " + command.toUpperCase()); 53 } 54 55 } 56 } 57 // Infrastructure fpr Some Simple Painting 58 public Interpreter2 () { 59 interpreter(); 60 } 61 62 public static void main(String[] args) { 63 SwingUtilities.invokeLater(new Runnable() { 64 @Override 65 public void run() { 66 new Interpreter2(); 67 } 68 }); 69 } 70 } 71