TicTacToe - HumenPlayer and MessageBox

HumenPlayer.java

import java.util.Random;
import java.io.*;

public class HumenPlayer

 TicTacToe Frame;

 public HumenPlayer(TicTacToe ref)
 {
  Frame=ref;
 }

 public void GameMove(int[][] GameTable,int i,int j)
 {
  int x,y;

  x=i;
  y=j;
  GameTable[x][y]=1;
  Frame.UpdateBoard();

 } 
}

MessageBox.java

// MessageBox - source from Dr. Kirsh site

import java.awt.*;
import java.awt.event.*;

public class MessageBox extends Frame
{
 public MessageBox(String message,
  String title)
 {
  addWindowListener(new ClosingHandler());
  addKeyListener(new EscHandler());
  setLayout(new BorderLayout(10, 10));
  setBackground(Color.lightGray);

  Label label = new Label(message, Label.CENTER);
  label.addKeyListener(new EscHandler());
  add(label, BorderLayout.CENTER);
  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. 
  setLocation(400,300); 
  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.