/*this interpreter is intended to paint different colored dots in a window The command that the interpreter can recognize and respond to are: - BLUE: paint a blue dot -RED: paint a red dot -Help: show a list of the commands in a dialog message box -EXIT: terminate the program */ package interpreters; import painter.SPainter; import shapes.SCircle; import javax.swing.*; import java.awt.*; public class Interpreter2 { private void Interpreter() { SPainter miro = new SPainter( " Dot Thing", 400,400); miro.setScreenLocation(0,0); SCircle dot = new SCircle(180); while (true){ String command = JOptionPane.showInputDialog(null, "Command?"); if (command == null){ command = "exit"; //user clicked on cancel } if (command.equalsIgnoreCase("blue")){ miro.setColor(Color.BLUE); miro.paint(dot); } else if (command.equalsIgnoreCase("red")){ miro.setColor(Color.red); miro.paint(dot); } else if (command.equalsIgnoreCase("green")){ miro.setColor(Color.green); miro.paint(dot); } else if (command.equalsIgnoreCase("yellow")){ miro.setColor(Color.yellow); miro.paint(dot); } else if (command.equalsIgnoreCase("help")){ JOptionPane.showMessageDialog(null,"valid commands are: " + "Green | Yellow | Red | Blue | Help | Exit " ); } else if (command.equalsIgnoreCase("exit")) { miro.end(); System.out.println("Thank you For viewing the dots ..."); break; }else{ JOptionPane.showMessageDialog(null, "Unrecognizable Command: " + command.toUpperCase()); } } } public Interpreter2() { Interpreter(); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new Interpreter2(); } }); } }