game
Class MapLabel
- 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.
MapLabel(ImageIcon imageIcon, int numDetectives)
|
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)
|
MapLabel
public MapLabel(ImageIcon imageIcon,
int numDetectives)
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.
player
- The player (0 = Mr. X, 1..n = detectives) whose position shall
be determined.
- 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.
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.
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)