1 /* BY PRESTON ELIA 2 * DATE SEP 21 2022 3 * 4 * this interpreter is intended to paint different colored dots in a window 5 * 6 * the commands that the interpreter recognized 7 * -> BLUE: paint blue dot 8 * -> RED: paint red dot 9 * -> HELP: show a list of commands 10 * -> EXIT: terminate the program 11 */ 12 13 14 package interpreters; 15 16 import java.awt.Color; 17 import javax.swing.JOptionPane; 18 import javax.swing.SwingUtilities; 19 import painter.SPainter; 20 import shapes.SCircle; 21 22 public class Interpreter1 { 23 24 private void interpreter() { 25 // CREATE OBJECTS TO THINK WITH 26 SPainter miro = new SPainter ("dot thing",400,400); 27 miro.setScreenLocation(0,0); 28 SCircle dot = new SCircle(180); 29 30 // REPEATEDLY TAKE COMMAND FROM AN INPUT DIALOG BOX AND INTERPRET IT 31 while (true) { 32 String command = JOptionPane.showInputDialog(null, "Command?"); 33 if (command == null) {command = "exist";} // user clicked cancel 34 if (command.equalsIgnoreCase("blue")) { 35 miro.setColor(Color.BLUE); 36 miro.paint(dot); 37 } else if (command.equalsIgnoreCase("red")) { 38 miro.setColor(Color.RED); 39 miro.paint(dot); 40 }else if (command.equalsIgnoreCase("help")) { 41 JOptionPane.showMessageDialog(null, "Valid Commands are: " + "|RED|BLUE|HELP|EXIT|"); 42 }else if (command.equalsIgnoreCase("exit")) { 43 miro.end(); 44 System.out.println("bye"); 45 break; 46 } else { 47 JOptionPane.showMessageDialog(null, "Not a command"+ command.toUpperCase()); 48 } 49 } 50 } 51 // INFRASTRUCTURE FOR PAINTING 52 public Interpreter1() { 53 interpreter(); 54 } 55 public static void main(String[] args) { 56 SwingUtilities.invokeLater(new Runnable() { 57 public void run() { 58 new Interpreter1(); 59 } 60 }); 61 } 62 } 63