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