1 package Interpreters; 2 3 import java.awt.Color; 4 import javax.swing.JOptionPane; 5 import javax.swing.SwingUtilities; 6 import painter.SPainter; 7 import shapes.SCircle; 8 9 public class Interpreter2 { 10 private void interpreter() { 11 12 SPainter miro = new SPainter("Dot",400,400); 13 miro.setScreenLocation(0,0); 14 SCircle dot = new SCircle(180); 15 16 while ( true ) { 17 String command = JOptionPane.showInputDialog(null,"Command?"); 18 if ( command == null ) { command = "exit"; } // user clicked on Cancel 19 if ( command.equalsIgnoreCase("blue") ) { 20 miro.setColor(Color.BLUE); 21 miro.paint(dot); 22 } else if ( command.equalsIgnoreCase("red") ) { 23 miro.setColor(Color.RED); 24 miro.paint(dot); 25 } else if ( command.equalsIgnoreCase("help") ) { 26 JOptionPane.showMessageDialog(null,"Valid commands are: " 27 + "RED | BLUE | Green | Yellow | Help | Exit "); 28 } else if (command.equalsIgnoreCase("green")) { 29 miro.setColor(Color.green); 30 miro.paint(dot); 31 } else if (command.equalsIgnoreCase("yellow")) { 32 miro.setColor(Color.yellow); 33 miro.paint(dot); 34 } else if ( command.equalsIgnoreCase("exit") ) { 35 miro.end(); 36 System.out.println("Thank you for viewing the dots ..."); 37 break; 38 } else { 39 JOptionPane.showMessageDialog(null, "Unrecognizable command: "+ command.toUpperCase()); 40 } 41 } 42 } 43 44 45 public Interpreter2() { 46 interpreter(); 47 } 48 49 public static void main(String[] args) { 50 SwingUtilities.invokeLater(new Runnable() { 51 public void run() { 52 new Interpreter2(); 53 } 54 }); 55 } 56 } 57 58