examples.tictactoe
Class TicTacToeAgent

java.lang.Object
  extended byexamples.tictactoe.TicTacToeAgent
All Implemented Interfaces:
ActionListener, EventListener, MouseInputListener, MouseListener, MouseMotionListener, Resumable, Runnable, Serializable, WindowListener

public class TicTacToeAgent
extends Object
implements Resumable, Serializable, ActionListener, WindowListener, MouseInputListener

This class is mobile code, which will migrate through the peer-network and enables user to exchange textmassages with each other.

Version:
"$Id: TicTacToeAgent.java 1913 2007-08-08 02:41:53Z jpeters $"
Author:
Andreas Reuter
See Also:
Serialized Form

Nested Class Summary
 class TicTacToeAgent.JIconButton
           
 
Field Summary
(package private) static String AWAY_STYLE
           
private  HighScoreEntry awayEntry_
           
private  String awayLocation_
           
private  JTextPane convHist_
           
private  JTextField convInput_
           
private  LinkedList convList_
           
private  int convListIndex_
           
(package private) static boolean DEBUG
           
(package private) static String DEFAULT_STYLE
           
private  String dest_
           
private  JButton destButton_
           
private  ImageIcon exitIcon_
           
private  ImageIcon exitIcon1_
           
private  JFrame gameFrame_
           
private  ImageIcon hideIcon_
           
private  ImageIcon hideIcon1_
           
private  ImageIcon hideIcon2_
           
private  ImageIcon hideIcon3_
           
(package private) static String HIGHSCORE_PATH
           
private  String home_
           
(package private) static String HOME_STYLE
           
private  HighScoreEntry homeEntry_
           
private  String homeLocation_
           
private static URL[] hosts_
           
private  ImageIcon icon_
           
private  ImageIcon iconO_
           
private  ImageIcon iconX_
           
(package private) static String IMAGE_PATH
           
private  JFrame initFrame_
           
private  Object lock_
           
private  MobilityContext mob_
           
private  AgentCard myCard_
           
private  ImageIcon opalIcon_
           
private  ImageIcon opalIconO_
           
private  ImageIcon opalIconX_
           
private  boolean printHighScore_
           
private  JComboBox serverChoiceBox_
           
private  ImageIcon showIcon_
           
private  ImageIcon showIcon1_
           
private  ImageIcon showIcon2_
           
private  ImageIcon showIcon3_
           
private  String source_
           
(package private) static String STATUS_STYLE
           
private  JPanel talkPane_
           
private  TicTacToeBoard tBoard_
           
private static boolean test_
           
private  ArrayList urls_
           
 
Constructor Summary
TicTacToeAgent()
          Creates an object of the class TicTacToeAgent
 
Method Summary
 void actionPerformed(ActionEvent aEvent)
          Defines the specific action sequence of all buttons of this class
private  JPanel createBoardPane()
           
private  JPanel createTalkPane()
          Method enables the user to create and read textmessages with th choosen chat-partner.
private  void drawBoardPart(Image img, int x, int y, int xWidth, int yWidth, Graphics g, Component comp)
           
private  void drawBoardPart(Image img, Rectangle rect, Graphics g, Component comp)
           
private  void drawBoardWinner(int winner, Graphics g, Component comp)
           
private  void drawHighScore(Graphics g, Component comp)
          Print the Highscore
private  ArrayList findTargets()
          Get a list of all peers found in the VICINITY-network
private  boolean gameEnd()
          Returns true if a game is at end
private  void gameGUI()
          Method enables the user to play with the choosen game-partner.
private  ImageIcon getImageFromResource(Resource resource, String name)
          Loads an Icon from Agent's Resource
private  void initGUI()
          Method enables the user to choose a game-partner in the VICINITY-network
private  boolean isHome()
          Get a list of all peers found in the VICINITY-network
private  LinkedList loadHighScore()
          Loads the Highscore
static void main(String[] argv)
          This method is used for the initial launch of the agent from the jshell.
 void mouseClicked(MouseEvent e)
           
 void mouseDragged(MouseEvent e)
           
 void mouseEntered(MouseEvent e)
           
 void mouseExited(MouseEvent e)
           
 void mouseMoved(MouseEvent e)
           
 void mousePressed(MouseEvent e)
           
 void mouseReleased(MouseEvent e)
           
private  void offerRevenge()
           
private  boolean printHighScore()
          Returns true if HighScore can be printed
private  LinkedList quicksort(LinkedList qsliste)
          Sortieralgorithmus
 void resume(ErrorCode err)
          After an agent was suspended on a peer, he will migrate to >null< and terminate.
 void run()
          This method will be executed after an agent has reached a peer.
private  void saveHighScore()
          Save the Highscore
private  LinkedList updatedHighScore()
          Save the Highscore
 void windowActivated(WindowEvent wEvent)
          Is not spezified in this program
 void windowClosed(WindowEvent wEvent)
          When window closed the agent will leave his locked state
 void windowClosing(WindowEvent wEvent)
          Dispose all windows and terminate agent
 void windowDeactivated(WindowEvent wEvent)
          Is not spezified in this program
 void windowDeiconified(WindowEvent wEvent)
          Is not spezified in this program
 void windowIconified(WindowEvent wEvent)
          Is not spezified in this program
 void windowOpened(WindowEvent wEvent)
          Is not spezified in this program
private static void writeImageToResource(Resource resource, String name)
          Writes an Image to Agent's Resource
private static void writeToResource(Resource resource, InputStream in, String name)
          writes a stream to resource with the identifying name
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

static final boolean DEBUG
See Also:
Constant Field Values

IMAGE_PATH

static final String IMAGE_PATH
See Also:
Constant Field Values

HIGHSCORE_PATH

static final String HIGHSCORE_PATH

STATUS_STYLE

static final String STATUS_STYLE
See Also:
Constant Field Values

HOME_STYLE

static final String HOME_STYLE
See Also:
Constant Field Values

AWAY_STYLE

static final String AWAY_STYLE
See Also:
Constant Field Values

DEFAULT_STYLE

static final String DEFAULT_STYLE
See Also:
Constant Field Values

initFrame_

private transient JFrame initFrame_

gameFrame_

private transient JFrame gameFrame_

serverChoiceBox_

private transient JComboBox serverChoiceBox_

mob_

private transient MobilityContext mob_

destButton_

private transient JButton destButton_

icon_

private transient ImageIcon icon_

opalIcon_

private transient ImageIcon opalIcon_

iconO_

private transient ImageIcon iconO_

iconX_

private transient ImageIcon iconX_

opalIconO_

private transient ImageIcon opalIconO_

opalIconX_

private transient ImageIcon opalIconX_

hideIcon_

private transient ImageIcon hideIcon_

hideIcon1_

private transient ImageIcon hideIcon1_

hideIcon2_

private transient ImageIcon hideIcon2_

hideIcon3_

private transient ImageIcon hideIcon3_

showIcon_

private transient ImageIcon showIcon_

showIcon1_

private transient ImageIcon showIcon1_

showIcon2_

private transient ImageIcon showIcon2_

showIcon3_

private transient ImageIcon showIcon3_

exitIcon_

private transient ImageIcon exitIcon_

exitIcon1_

private transient ImageIcon exitIcon1_

convHist_

private transient JTextPane convHist_

convInput_

private transient JTextField convInput_

talkPane_

private transient JPanel talkPane_

printHighScore_

private transient boolean printHighScore_

homeLocation_

private String homeLocation_

awayLocation_

private String awayLocation_

hosts_

private static URL[] hosts_

test_

private static boolean test_

homeEntry_

private HighScoreEntry homeEntry_

awayEntry_

private HighScoreEntry awayEntry_

convList_

private LinkedList convList_

urls_

private ArrayList urls_

convListIndex_

private int convListIndex_

home_

private String home_

source_

private String source_

dest_

private String dest_

lock_

private Object lock_

myCard_

private AgentCard myCard_

tBoard_

private TicTacToeBoard tBoard_
Constructor Detail

TicTacToeAgent

public TicTacToeAgent()
Creates an object of the class TicTacToeAgent

Method Detail

resume

public void resume(ErrorCode err)
After an agent was suspended on a peer, he will migrate to >null< and terminate.

Specified by:
resume in interface Resumable
Parameters:
err - ErrorCode Error, which is appeared during the program execution

run

public void run()
This method will be executed after an agent has reached a peer. The agents behaviour depends on some variable values

Specified by:
run in interface Runnable
Throws:
InterruptedException - Interrupts the wait-state of the agent

gameEnd

private boolean gameEnd()
Returns true if a game is at end


printHighScore

private boolean printHighScore()
Returns true if HighScore can be printed


initGUI

private void initGUI()
Method enables the user to choose a game-partner in the VICINITY-network


createTalkPane

private JPanel createTalkPane()
Method enables the user to create and read textmessages with th choosen chat-partner.

Throws:
Exception - If a problem with the inet-addresses happens

gameGUI

private void gameGUI()
Method enables the user to play with the choosen game-partner.

Throws:
Exception - If a problem with the inet-addresses happens

drawBoardPart

private void drawBoardPart(Image img,
                           int x,
                           int y,
                           int xWidth,
                           int yWidth,
                           Graphics g,
                           Component comp)

drawBoardPart

private void drawBoardPart(Image img,
                           Rectangle rect,
                           Graphics g,
                           Component comp)

offerRevenge

private void offerRevenge()

drawBoardWinner

private void drawBoardWinner(int winner,
                             Graphics g,
                             Component comp)

createBoardPane

private JPanel createBoardPane()

actionPerformed

public void actionPerformed(ActionEvent aEvent)
Defines the specific action sequence of all buttons of this class

Specified by:
actionPerformed in interface ActionListener
Parameters:
aEvent - ActionEvent An event from one of the GUI components.
Throws:
Exception - If there are migration problems

windowClosed

public void windowClosed(WindowEvent wEvent)
When window closed the agent will leave his locked state

Specified by:
windowClosed in interface WindowListener
Parameters:
wEvent - WindowEvent An event from one of the windows.

windowClosing

public void windowClosing(WindowEvent wEvent)
Dispose all windows and terminate agent

Specified by:
windowClosing in interface WindowListener
Parameters:
wEvent - WindowEvent An event from one of the windows.

windowActivated

public void windowActivated(WindowEvent wEvent)
Is not spezified in this program

Specified by:
windowActivated in interface WindowListener
Parameters:
wEvent - WindowEvent An event from one of the windows.

windowDeactivated

public void windowDeactivated(WindowEvent wEvent)
Is not spezified in this program

Specified by:
windowDeactivated in interface WindowListener
Parameters:
wEvent - WindowEvent An event from one of the windows.

windowDeiconified

public void windowDeiconified(WindowEvent wEvent)
Is not spezified in this program

Specified by:
windowDeiconified in interface WindowListener
Parameters:
wEvent - WindowEvent An event from one of the windows.

windowIconified

public void windowIconified(WindowEvent wEvent)
Is not spezified in this program

Specified by:
windowIconified in interface WindowListener
Parameters:
wEvent - WindowEvent An event from one of the windows.

windowOpened

public void windowOpened(WindowEvent wEvent)
Is not spezified in this program

Specified by:
windowOpened in interface WindowListener
Parameters:
wEvent - WindowEvent An event from one of the windows.

isHome

private boolean isHome()
Get a list of all peers found in the VICINITY-network

Returns:
List of all peers which were found in the VICINITY network

mouseClicked

public void mouseClicked(MouseEvent e)
Specified by:
mouseClicked in interface MouseListener

mouseDragged

public void mouseDragged(MouseEvent e)
Specified by:
mouseDragged in interface MouseMotionListener

mouseEntered

public void mouseEntered(MouseEvent e)
Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent e)
Specified by:
mouseExited in interface MouseListener

mousePressed

public void mousePressed(MouseEvent e)
Specified by:
mousePressed in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent e)
Specified by:
mouseReleased in interface MouseListener

mouseMoved

public void mouseMoved(MouseEvent e)
Specified by:
mouseMoved in interface MouseMotionListener

findTargets

private ArrayList findTargets()
Get a list of all peers found in the VICINITY-network

Returns:
List of all peers which were found in the VICINITY network

writeToResource

private static void writeToResource(Resource resource,
                                    InputStream in,
                                    String name)
writes a stream to resource with the identifying name

Parameters:
in - The InputStream to read from
name - The name identifying the data of which an output stream is requested

writeImageToResource

private static void writeImageToResource(Resource resource,
                                         String name)
Writes an Image to Agent's Resource


quicksort

private LinkedList quicksort(LinkedList qsliste)
Sortieralgorithmus


drawHighScore

private void drawHighScore(Graphics g,
                           Component comp)
Print the Highscore


updatedHighScore

private LinkedList updatedHighScore()
Save the Highscore


saveHighScore

private void saveHighScore()
Save the Highscore


loadHighScore

private LinkedList loadHighScore()
Loads the Highscore


getImageFromResource

private ImageIcon getImageFromResource(Resource resource,
                                       String name)
Loads an Icon from Agent's Resource


main

public static void main(String[] argv)
This method is used for the initial launch of the agent from the jshell.



Copyright © Fraunhofer Gesellschaft. All Rights Reserved.