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 Interpreter1 { 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 | HELP | EXIT "); 28 } else if ( command.equalsIgnoreCase("exit") ) { 29 miro.end(); 30 System.out.println("Thank you for viewing the dots ..."); 31 break; 32 } else { 33 JOptionPane.showMessageDialog(null, "Unrecognizable command: "+ command.toUpperCase()); 34 } 35 } 36 } 37 38 public Interpreter1() { 39 interpreter(); 40 } 41 public static void main(String[] args) { 42 SwingUtilities.invokeLater(new Runnable() { 43 public void run() { 44 new Interpreter1(); 45 } 46 }); 47 } 48 } 49 50