game

Class MapLabel

Implemented Interfaces:
ActionListener

public class MapLabel
extends JLabel
implements ActionListener

This class extends the JLabel class to provide the functionality of overlaying images (positions of detectives) on top of the game board.
Version:
2.4 (19-APR-2010)
Author:
Johannes Jowereit

Constructor Summary

MapLabel(ImageIcon imageIcon, int numDetectives)

Method Summary

Point
getPlayerPos(int player)
Gets the position of the given player's current position on screen.
void
paint(Graphics g)
void
repaintPlayerPos(int player)
Repaints the area in which the position of the given player lies.
void
setCurrentPlayer(int player)
Sets the currently active player and takes care of the blinking of the current player's position.
void
setPlayerPos(int player, Point pos)
void
setPlayerPos(int player, int x, int y)
@Override
void actionPerformed(ActionEvent evt)

Constructor Details

MapLabel

public MapLabel(ImageIcon imageIcon,
                int numDetectives)

Method Details

getPlayerPos

public Point getPlayerPos(int player)
Gets the position of the given player's current position on screen. The label may be bigger than the image contained in it, in which case the image will be centered. In this case, an offset has to be added to the position retrieved in the playerPositions[] array. FIXME: Store xOffset and yOffset in private fields and only change them when the label's size changes.
Parameters:
player - The player (0 = Mr. X, 1..n = detectives) whose position shall be determined.
Returns:
The pixel coordinates of the player's position.

paint

public void paint(Graphics g)

repaintPlayerPos

public void repaintPlayerPos(int player)
Repaints the area in which the position of the given player lies.
Parameters:
player - The number of the detective, or 0 for Mr. X

setCurrentPlayer

public void setCurrentPlayer(int player)
Sets the currently active player and takes care of the blinking of the current player's position.
Parameters:
player - The number of the new currently active player.

setPlayerPos

public void setPlayerPos(int player,
                         Point pos)

setPlayerPos

public void setPlayerPos(int player,
                         int x,
                         int y)

void actionPerformed

public @Override void actionPerformed(ActionEvent evt)