Java Reference
In-Depth Information
8.
private
BlockPuzzlePanel bpPanel;
9.
10.
BlockPuzzleListener (BlockPuzzlePanel bp, DirectionPanel m){
11.
dirPanel = m;
12.
bpPanel = bp;
13.
}
14.
15.
public void
mouseClicked(MouseEvent evt){
16.
//
17.
int
x= evt.getX();
18.
int
y= evt.getY();
19.
int
blockNo = bpPanel.getBlockNoAtPixels(x,y);
20.
//
Constructs the move
21.
MoveModel move =
22.
new
MoveModel(dirPanel.getDirection(),blockNo);
23.
//
Request a move to made be in the BlockPuzzlePanel.
24.
//
Note that the BlockPuzzleListener does not know HOW to make
25.
//
a move.
26.
bpPanel.makeMove(move);
27.
}
28.
29.
}
The driver class
BlockPuzzle
creates a
BlockPuzzleFrame
and makes it visible.
A screen shot of the program is shown in Figure 14.3.
Figure 14.3 The block puzzle application after some moves have been made
Search WWH ::
Custom Search