1 package interpreters; 2 3 import java.awt.Color; 4 import javax.swing.SwingUtilities; 5 6 import painter.SPainter; 7 import shapes.SCircle; 8 9 import javax.swing.JOptionPane; 10 11 public class Interpreter2 { 12 13 14 private void interpreter() { 15 16 //create oblects to think with 17 18 SPainter micro = new SPainter("Dot Thing", 400, 400); 19 micro.setScreenLocation(0, 0); 20 SCircle dot = new SCircle(180); 21 22 //repeatedly take a comand from an input dialog box and interpret it 23 24 while (true) { 25 26 String comand = JOptionPane.showInputDialog(null, "Comand?"); 27 if (comand == null) { 28 comand = "exit"; 29 } //user clicked on cancel 30 31 if (comand.equalsIgnoreCase("blue")) { 32 micro.setColor(Color.blue); 33 micro.paint(dot); 34 } else if (comand.equalsIgnoreCase("red")) { 35 micro.setColor(Color.red); 36 micro.paint(dot); 37 } else if (comand.equalsIgnoreCase("green")) { 38 micro.setColor(Color.green); 39 micro.paint(dot); 40 } else if (comand.equalsIgnoreCase("yellow")) { 41 micro.setColor(Color.yellow); 42 micro.paint(dot); 43 44 45 } else if (comand.equalsIgnoreCase("help")) { 46 47 JOptionPane.showMessageDialog(null, "vallid comands are:" 48 + "RED / BLUE / YELLOW / GREEN / HELP / EXIT "); 49 50 } else if (comand.equalsIgnoreCase("exit")) { 51 52 53 micro.end(); 54 System.out.println("Thank you for viewing the dots ..."); 55 break; 56 57 58 } else { 59 JOptionPane.showMessageDialog(null, "Unrecognizqable comand:" + comand.toUpperCase()); 60 } 61 62 63 } 64 } 65 66 67 //infastructure for painting 68 69 public Interpreter2() { 70 71 interpreter(); 72 } 73 74 75 public static void main(String[] args) { 76 SwingUtilities.invokeLater(new Runnable() { 77 public void run() { 78 new Interpreter2(); 79 } 80 81 82 }); 83 } 84 } 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99