Interpreter1.java
1    /* 
2     * Program takes an input from a user (RED | BLUE | 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 Interpreter1
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("help") )
39               {
40                   JOptionPane.showMessageDialog(null, "Valid command are: " + "RED | BLUE | HELP | EXIT");
41               }
42               else if ( command.equalsIgnoreCase("exit") )
43               {
44                   miro.end();
45                   System.out.println("Thank you for viewing the dots ...");
46                   break;
47               }
48               else {
49                   JOptionPane.showMessageDialog(null, "Unrecognizable command: " + command.toUpperCase());
50               }
51           }
52       }
53   
54       //  INFRASTRUCTURE FOR SOME SIMPLE PAINTING
55   
56   
57       public Interpreter1()
58       {
59           interpreter();
60       }
61   
62       public static void main(String[] args)
63       {
64           SwingUtilities.invokeLater(new Runnable()
65           {
66               public void run()
67               {
68                   new Interpreter3();
69               }
70           });
71       }
72   }
73