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