/* this interpreter is indeed to paint different colored dots in a window. the commands that the interpreter can recongnize 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 Interpreter1 { private void interpreter() { //create objects to think with SPainter miro = new SPainter("Dot Things",400,400); miro.setScreenLocation(0,0); SCircle dot = new SCircle(180); //REPEATEDLY TAKE A COMMAND FROM AN INPUT DIALOG BOX AND INTERPREAT IT while (true) { String command= JOptionPane.showInputDialog(null,"Command?"); if (command == null){ command = "Exit";} //user click 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("help")) { JOptionPane.showMessageDialog(null, "Valid commands are: " + "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: "); } } } //INFRASTRUCTURE FOR SOME SIMPLE PAINTNG public Interpreter1() { interpreter(); } public static void main(String[] args){ SwingUtilities.invokeLater(new Runnable(){ public void run (){ new Interpreter1(); } }); } }