TicTacToe - TurnDialog

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

Java Programming

See also
Logic For Graphs using JFreeChart

Do you have a Java Problem?
Ask It in The Java Forum

Java Books
Java Certification, Programming, JavaBean and Object Oriented Reference Books

Return to : Java Programming Hints and Tips

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.