1 /* 2 *This interpreter is intended to paint different colored dots in a window. 3 */ 4 package interpreters; 5 6 import java.awt.Color; 7 import javax.swing.JOptionPane; 8 import javax.swing.SwingUtilities; 9 import painter.SPainter; 10 import shapes.SCircle; 11 12 public class Interpreter1 { 13 14 private void interpreter() { 15 16 //Create objects to thikn with 17 SPainter miro = new SPainter("Dot Thing", 400, 400); 18 miro.setScreenLocation(0, 0); 19 SCircle dot = new SCircle(180); 20 21 //Repeatedly take a command from an input dialog box and interpret it 22 23 while (true) { 24 String command = JOptionPane.showInputDialog(null, "Command?"); 25 if (command == null) { 26 command = "exit"; 27 } // user clicked on 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 } 47 48 49 // INFRASTRUCTURE FOR SOME SIMPLE PAINTING 50 51 public Interpreter1() { 52 interpreter(); 53 } 54 55 public static void main(String[] args) { 56 SwingUtilities.invokeLater(new Runnable() { 57 public void run() { 58 new Interpreter1(); 59 } 60 }); 61 } 62 } 63