1 /* 2 * Program takes an input from a user (RED | BLUE | GREEN | YELLOW | HELP | EXIT) and draws/exits based on user input. 3 * Created by Hunter Gersitz on 26 SEP 2019 ~ SUNY Oswego Fall 2019 4 */ 5 6 package interpreters; 7 8 import painter.SPainter; 9 import shapes.SCircle; 10 11 import javax.swing.*; 12 import java.awt.*; 13 14 public class Interpreter2 15 { 16 private void interpreter() 17 { 18 // CREATE OBJECTS TO THINK WITH 19 SPainter miro = new SPainter("Dot Thing", 400, 400); 20 miro.setScreenLocation(0,0); 21 SCircle dot = new SCircle(180); 22 23 // REPEATEDLY TAKE A COMMAND FROM AN INPUT DIALOG AND INTERPRET IT 24 while ( true ) 25 { 26 String command = JOptionPane.showInputDialog(null, "Command?"); 27 if ( command == null ) { command = "exit"; } // user clicked on Cancel 28 if ( command.equalsIgnoreCase("blue") ) 29 { 30 miro.setColor(Color.BLUE); 31 miro.paint(dot); 32 } 33 else if ( command.equalsIgnoreCase("red") ) 34 { 35 miro.setColor(Color.RED); 36 miro.paint(dot); 37 } 38 else if ( command.equalsIgnoreCase("green") ) 39 { 40 miro.setColor(Color.GREEN); 41 miro.paint(dot); 42 } 43 else if ( command.equalsIgnoreCase("yellow") ) 44 { 45 miro.setColor(Color.YELLOW); 46 miro.paint(dot); 47 } 48 else if ( command.equalsIgnoreCase("help") ) 49 { 50 JOptionPane.showMessageDialog(null, "Valid command are: " + "RED | BLUE | GREEN | YELLOW | HELP | EXIT"); 51 } 52 else if ( command.equalsIgnoreCase("exit") ) 53 { 54 miro.end(); 55 System.out.println("Thank you for viewing the dots ..."); 56 break; 57 } 58 else { 59 JOptionPane.showMessageDialog(null, "Unrecognizable command: " + command.toUpperCase()); 60 } 61 } 62 } 63 64 // INFRASTRUCTURE FOR SOME SIMPLE PAINTING 65 66 67 public Interpreter2() 68 { 69 interpreter(); 70 } 71 72 public static void main(String[] args) 73 { 74 SwingUtilities.invokeLater(new Runnable() 75 { 76 public void run() 77 { 78 new Interpreter3(); 79 } 80 }); 81 } 82 } 83