1 package interpreters; 2 3 import painter.SPainter; 4 import shapes.SCircle; 5 6 import javax.swing.*; 7 import java.awt.*; 8 9 public class Interpreters2 { 10 private void interpreter() { 11 SPainter miro = new SPainter("Dot Thing", 400, 400); 12 miro.setScreenLocation(0, 0); 13 SCircle dot = new SCircle(180); 14 15 while (true) { 16 String command = JOptionPane.showInputDialog(null, "Command?"); 17 if (command == null) { 18 command = "exit"; 19 } 20 if (command.equalsIgnoreCase("blue")) { 21 miro.setColor(Color.BLUE); 22 miro.paint(dot); 23 } else if (command.equalsIgnoreCase("red")) { 24 miro.setColor(Color.RED); 25 miro.paint(dot); 26 } else if (command.equalsIgnoreCase("green")) { 27 miro.setColor(Color.green); 28 miro.paint(dot); 29 } else if (command.equalsIgnoreCase("yellow")) { 30 miro.setColor(Color.yellow); 31 miro.paint(dot); 32 } else if (command.equalsIgnoreCase("help")) { 33 JOptionPane.showMessageDialog(null, "Valid commands are :" + "RED | BLUE | GREEN | YELLOW | HELP | EXIT "); 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 public Interpreters2() { 45 interpreter(); 46 } 47 48 public static void main (String[] args ) { 49 SwingUtilities.invokeLater(new Runnable() { 50 public void run() { 51 new Interpreters2(); 52 } 53 }); 54 } 55 }