Java Reference
In-Depth Information
15.
upBut
= new JRadioButton("up");
16.
downBut = new JRadioButton("down");
17.
lBut
= new JRadioButton("left");
18.
rBut
= new JRadioButton("right");
19.
20.
upBut.setActionCommand("u");
21.
downBut.setActionCommand("d");
22.
lBut.setActionCommand("l");
23.
rBut.setActionCommand("r");
24.
25.
group = new ButtonGroup();
26.
group.add(upBut);
27.
group.add(downBut);
28.
group.add(lBut);
group.add(rBut);
29.
upBut.setSelected( true );
30.
31.
32.
this .add(upBut);
this .add(downBut);
33.
this .add(lBut);
34.
this .add(rBut);
35.
}
36.
37.
38.
public int getDirection(){
39.
String actionCommand = group.getSelection().getActionCommand();
40.
int result = 0;
41.
if (actionCommand.equals("u")){
42.
result = Constants.DIRECTION_UP;
43.
} else if (actionCommand.equals("d")){
44.
result = Constants.DIRECTION_DOWN;
45.
} else if (actionCommand.equals("r")){
46.
result = Constants.DIRECTION_RIGHT;
47.
} else if (actionCommand.equals("l")){
48.
result = Constants.DIRECTION_LEFT;
49.
}
50.
return ( result );
}
51.
}
52.
The class BlockPuzzleFrame is not derived from SimpleFrame but from JFrame
to make this project independent of the its -package. In order to use it on its
own, one has to replace the package name its.BlockPuzzle by BlockPuzzle .
The frame implements a window listener, which terminates the application when
the frame is closed; see Section 9.3.
Search WWH ::




Custom Search