/home/ssingh6/NetBeansProjects/CS1/src/interpreters/Interpreter3.java
 1 /*
 2  * To change this license header, choose License Headers in Project Properties.
 3  * To change this template file, choose Tools | Templates
 4  * and open the template in the editor.
 5  */
 6 package interpreters;
 7 import javax.swing.JOptionPane;
 8 import java.awt.Color;
 9 import javax.swing.SwingUtilities;
10 import painter.SPainter;
11 import shapes.SCircle;
12 /**
13  *
14  * @author ssingh6
15  */
16 public class Interpreter3 {
17      private void interpreter()
18     {
19         SPainter micro = new SPainter("Dot Thing",400,400);
20         micro.setScreenLocation(0,0);
21         SCircle dot = new SCircle(180);
22         while(true)
23         {
24             String command = JOptionPane.showInputDialog(null,"Command?");
25             if(command==null) { command="exit"; } // user clicked Cancel
26             if(command.equalsIgnoreCase("blue"))
27             {
28                 micro.setColor(Color.BLUE);
29                 micro.paint(dot);
30             }
31             else if(command.equalsIgnoreCase("red"))
32             {
33                 micro.setColor(Color.RED);
34                 micro.paint(dot);
35             }
36             else if(command.equalsIgnoreCase("green"))
37             {
38                 micro.setColor(Color.GREEN);
39                 micro.paint(dot);
40             }
41             else if(command.equalsIgnoreCase("yellow"))
42             {
43                 micro.setColor(Color.YELLOW);
44                 micro.paint(dot);
45             }
46             else if(command.equalsIgnoreCase("random"))
47             {
48                 micro.setColor(randomColor());
49                 micro.paint(dot);
50                 
51             }
52             else if(command.equalsIgnoreCase("help"))
53             {
54                 JOptionPane.showMessageDialog(null," Valid comments are :"+"RED|BLUE|GREEN|YELLOW|RANDOM|HELP|EXIT");
55             }
56             else if(command.equalsIgnoreCase("exit"))
57             {
58                 micro.end();
59                 System.out.println("Thank You for viewing the dots...");
60                 break;
61                 
62             }
63             else
64             {
65                 JOptionPane.showMessageDialog(null, "Unrecognizable command:"+command.toUpperCase());
66             }
67         }
68     }
69 
70     public Interpreter3()
71     {
72         interpreter();
73     }
74     public static void main(String[] args) {
75         SwingUtilities.invokeLater(new Runnable(){
76             public void run() {
77                 new Interpreter3();
78             }
79         });
80     }
81 
82     private static  Color randomColor() {
83     int rv = (int) (Math.random()*256);
84     int gv= (int) (Math.random()*256);
85     int bv = (int) (Math.random()*256);
86     return new Color(rv,gv,bv);
87     
88 }
89 }