package interpreters; import painter.SPainter; import shapes.SCircle; import javax.swing.*; import java.awt.*; public class Interpreter2 { private void interpreter() { // Create Objects To Think With SPainter micro = new SPainter("Dot Thing",400,400); micro.setScreenLocation(0,0); SCircle dot = new SCircle(180); // REPEATEDLY TAKE A COMMAND FROM AN INOUT DIALOG BOX AND INTERPRET IT while (true) { String command = JOptionPane.showInputDialog(null,"Command?"); if ( command == null) { command = "exit"; } if ( command.equalsIgnoreCase("blue")) { micro.setColor(Color.BLUE); micro.paint(dot); } else if ( command.equalsIgnoreCase("red")) { micro.setColor(Color.RED); micro.paint(dot); } else if ( command.equalsIgnoreCase("green")) { micro.setColor(Color.GREEN); micro.paint(dot); } else if ( command.equalsIgnoreCase("yellow")) { micro.setColor(Color.YELLOW); micro.paint(dot); } else if ( command.equals("help")) { JOptionPane.showMessageDialog(null, "Valid command are: " + "RED | BLUE | GREEN | YELLOW | HELP | EXIT "); } else if (command.equalsIgnoreCase("exit")) { micro.end(); System.out.println("Thank you for viewing the dots ..."); break; } else { JOptionPane.showMessageDialog(null, "Unrecognizable 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(); } }); } }