Java Reference
In-Depth Information
File:
its/BlockPuzzle/BlockPuzzleFrame.java
1.
package
its.BlockPuzzle;
2.
3.
4.
import
java.awt.event.WindowAdapter;
5.
import
java.awt.event.WindowEvent;
6.
import
java.awt.BorderLayout;
7.
import
javax.swing.JFrame;
8.
9.
10.
public class
BlockPuzzleFrame
extends
JFrame
11.
{
12.
private
DirectionPanel dirPanel;
13.
private
BlockPuzzlePanel bpPanel;
14.
15.
//
Constructor
16.
public
BlockPuzzleFrame(
int
rows,
int
cols) {
17.
18.
this
.setLocation(200,200);
19.
this
.setTitle("ITS Block Puzzle");
20.
BoardModel boardMod =
new
BoardModel(rows,cols);
21.
bpPanel =
new
BlockPuzzlePanel(boardMod);
22.
dirPanel =
new
DirectionPanel();
23.
getContentPane().add(bpPanel,BorderLayout.CENTER);
24.
getContentPane().add(dirPanel,BorderLayout.EAST);
25.
26.
BlockPuzzleListener bpList =
new
BlockPuzzleListener(bpPanel,dirPanel);
27.
bpPanel.addMouseListener(bpList);
28.
29.
//
Correct termination:
30.
//
Otherwise only the frame disappears when clicking
31.
//
on the ”close” symbol but the process keeps running.
32.
addWindowListener(
new
WindowAdapter()
33.
{
public void
windowClosing(WindowEvent e)
34.
{
35.
System.exit(0);
36.
}
37.
});
38.
pack();
39.
}
40.
41.
42.
public void
showIt(){
43.
this
.setVisible(
true
);
44.
}
Search WWH ::
Custom Search