import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.Enumeration;
public class MazeControlPanel extends Applet implements ActionListener
{
Button Gr,Bu,Bl;
Button Nw,So,Sd;
MazeApplet target;
TextField tbDiff;
public void init()
{
setLayout(new GridLayout(6,1));
add(new Label("Wall Color",Label.CENTER));
Panel p = new Panel();
p.setLayout(new GridLayout(1,3));
Gr = new Button("Green");
Gr.addActionListener(this);
Gr.setActionCommand("gr");
Bu = new Button("Blue");
Bu.addActionListener(this);
Bu.setActionCommand("bu");
Bl = new Button("Black");
Bl.addActionListener(this);
Bl.setActionCommand("bl");
p.add(Bl);
p.add(Gr);
p.add(Bu);
add(p);
Panel p1 = new Panel();
add(new Label("Difficultly", Label.CENTER));
Sd = new Button("Set");
Sd.addActionListener(this);
Sd.setActionCommand("sd");
tbDiff= new TextField();
p1.setLayout(new GridLayout(1,2));
p1.add(tbDiff);
p1.add(Sd);
add(p1);
add(new Label("Commands",Label.CENTER));
Panel p2 = new Panel();
p2.setLayout(new GridLayout(1,3));
Nw = new Button("New Maze");
Nw.addActionListener(this);
Nw.setActionCommand("nw");
So = new Button("Start Over");
So.addActionListener(this);
So.setActionCommand("so");
p2.add(Nw);
p2.add(new Label(" "));
p2.add(So);
add(p2);
//return all applets on this page
Enumeration e=getAppletContext().getApplets();
while(e.hasMoreElements())
{
Applet applet = (Applet)e.nextElement();
if(applet instanceof MazeApplet)
{
target = (MazeApplet)applet;
break;
}
}
if (target == null)
{
showStatus("A MazeApplet was not Found");
}
}
public void actionPerformed(ActionEvent e)
{
String str = e.getActionCommand();
if (str.equals("bl"))
target.setColor(Color.black);
else if (str.equals("bu"))
target.setColor(Color.blue);
else if(str.equals("gr"))
target.setColor(Color.green);
else if(str.equals("nw"))
target.NewMaze();
else if(str.equals("so"))
target.reset();
else if(str.equals("sd"))
{
int diff = 0;
try
{
diff = Integer.parseInt(tbDiff.getText());
}
catch(NumberFormatException ne){}
if (diff > 2)
target.setDiff(diff);
}
}
}