import java.awt.*;
import java.awt.event.*;
public class TurnDialog extends Dialog
{
Choice X;
Choice Y;
public TurnDialog(Frame parent)
{
super(Frame,"Play Your Move",true);
addWindowListener(new ClosingHandler());
addKeyListener(new EscHandler());
setLayout(new BorderLayout(10, 10));
setBackground(Color.lightGray);
Label label=new Label("Choose your next move: ");
label.addKeyListener(new EscHandler());
add(label, BorderLayout.WEST);
X=new Choice();
Y=new Choice();
for(int i=0;i<3;i++){
X.addItem(Integer.toString(i+1));
Y.addItem(Integer.toString(i+1));
}
add(X,BorderLayout.CENTER);
add(Y,BorderLayout.EAST);
Panel buttonsPanel = new Panel();
buttonsPanel.addKeyListener(new EscHandler());
Button ok = new Button("OK");
buttonsPanel.add(ok);
ok.addActionListener(new OkHandler());
ok.addKeyListener(new EscHandler());
add(buttonsPanel, BorderLayout.SOUTH);
pack(); // take minimum necessary size.
Rectangle fRect = parent.getBounds();
Dimension dSize = getSize();
int x = fRect.x + (fRect.width - dSize.width)
/ 2;
int y = fRect.y + (fRect.height - dSize.height)
/ 2;
setLocation(x, y);
setVisible(true);
}
class ClosingHandler extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
dispose();
}
}
class EscHandler extends KeyAdapter
{
public void keyPressed(KeyEvent e)
{
if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
dispose();
}
}
class OkHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
dispose();
}
}
}
Related files:
TicTacToe.java
ANNPlayer.java
NueralNet.java
HumenPlayer.java
MessageBox.java
TurnDialog.java
Applet1.java |