1 /* 2 * This program is intended to paint different colored dots in a window 3 */ 4 5 package interpreters; 6 7 import painter.SPainter; 8 import shapes.SCircle; 9 10 import javax.swing.*; 11 import java.awt.*; 12 13 public class Interpreter1 { 14 private void interpreter() { 15 // create objects to think with 16 SPainter micro = new SPainter("Dot Thing",400,400); 17 micro.setScreenLocation(0,0); 18 SCircle dot = new SCircle(180); 19 20 //repeatedly take a command from an inpit dialog box and interpret it 21 22 while (true) { 23 String command = JOptionPane.showInputDialog(null,"Command?"); 24 if (command==null) { command = "exit"; } //user clicked on cancel 25 if (command.equalsIgnoreCase("blue") ) { 26 micro.setColor(Color.blue); 27 micro.paint(dot); 28 } else if (command.equalsIgnoreCase("red")) { 29 micro.setColor(Color.red); 30 micro.paint(dot); 31 } else if (command.equalsIgnoreCase("help")) { 32 JOptionPane.showMessageDialog(null,"Valid commands are: " + "RED | BLUE | HELP | EXIT"); 33 34 } else if (command.equalsIgnoreCase("exit")) { 35 micro.end(); 36 System.out.println("Thank you for viewing the dots..."); 37 break; 38 39 } else { 40 JOptionPane.showMessageDialog(null, "Unrecognizable command: " + command.toUpperCase()); 41 42 } 43 } 44 } 45 // Infrastructure for some simple painting 46 47 public Interpreter1() { 48 interpreter(); 49 50 } 51 public static void main(String[] args) { 52 SwingUtilities.invokeLater(new Runnable() { 53 public void run() { 54 new Interpreter1(); 55 56 } 57 }); 58 } 59 } 60 61