/* *This interpreter is intended to paint differernt colored dots in a window * * the commands 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 java.awt.Color; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import painter.SPainter; import shapes.SCircle; public class Interpreter2 { private void Interpreter() { //CREATE OBJECTS TO THINK WITH SPainter miro = new SPainter("Dot Thing", 400, 400); miro.setScreenLocation(0, 0); SCircle dot = new SCircle(180); //REPEATEDLY TAKE A COMMAND FROM AN INPUT DIALOG BOX AND INTERPRET IT \ 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: " + "RED | BLUE | GREEN | YELLOW | HELP | EXIT "); } else if (command.equalsIgnoreCase("Exit")) { miro.end(); System.out.println("Thank you for viewing dots..."); break; } else { JOptionPane.showMessageDialog(null, "Unregnizable command;" + command.toUpperCase()); } } } //INFRASTRUCTURE FOR SOME SIMPLE PAINTING public Interpreter2() { Interpreter(); } public static void main (String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new Interpreter2(); } }); } }