1 package interpreters; 2 3 import java.awt.Color; 4 import javax.swing.JOptionPane; 5 import javax.swing.SwingUtilities; 6 import painter.SPainter; 7 import shapes.SCircle; 8 9 public class Interpreter2 { 10 11 private void interpreter() { 12 13 SPainter miro = new SPainter("Dot Thing", 400, 400); 14 miro.setScreenLocation(0, 0); 15 SCircle dot = new SCircle(180); 16 17 while (true) { 18 String command = JOptionPane.showInputDialog(null, "Command?"); 19 if (command == null) { 20 command = "exit"; 21 } 22 if (command.equalsIgnoreCase("red")) { 23 miro.setColor(Color.RED); 24 miro.paint(dot); 25 } else if (command.equalsIgnoreCase("blue")) { 26 miro.setColor(Color.BLUE); 27 miro.paint(dot); 28 } else if (command.equalsIgnoreCase("green")) { 29 miro.setColor(Color.GREEN); 30 miro.paint(dot); 31 } else if (command.equalsIgnoreCase("yellow")) { 32 miro.setColor(Color.YELLOW); 33 miro.paint(dot); 34 } else if (command.equalsIgnoreCase("help")) { 35 JOptionPane.showMessageDialog(null, "Valid commands are: " + "RED | BLUE | GREEN | YELLOW | 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 public Interpreter2() { 48 interpreter(); 49 50 } 51 52 public static void main(String[] args) { 53 SwingUtilities.invokeLater(new Runnable() { 54 public void run() { 55 new Interpreter2(); 56 } 57 }); 58 } 59 } 60