/* * This interpreter is intended to paint different colored dots in a window. * * The commands that the interpreter can recgonzie and respond to are: * - BLUE: paint a blue dot * - RED : paint a red dot * - HELP : show a list of the commands in a dailog 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 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("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,"Unrecongizeable Command : " + command.toUpperCase()); } } } //INFRASTRCUTURE FOR SOME SIMPLE PAINTING public interpreter1() { interpreter(); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new interpreter1(); } }); } }