Java Reference
In-Depth Information
53.
}
54.
55.
private void drawBlock( int r, int c, int n, Graphics g){
56.
g.drawRect(c*columnWidth+2,r*rowHeight+2,columnWidth-4,
57.
rowHeight-4);
58.
g.drawString(""+n,c*columnWidth+(columnWidth/2),
59.
r*rowHeight+rowHeight/2);
60.
}
61.
62.
private void drawMissingBlock( int r, int c, Graphics g){
63.
g.fillRect(c*columnWidth,r*rowHeight,columnWidth,rowHeight);
64.
}
65.
66.
public int getBlockNoAtPixels( int x, int y){
67.
int c= x/( this .getWidth()/noOfCols);
68.
int r= y/( this .getHeight()/noOfRows);
69.
return (currentConf.getBlockNo(r,c));
70.
}
71. }
Class DirectionPanel is quite simple. It receives a 4
1 grid layout, into which
four radio buttons are placed. They are labelled with the four directions and receive
action commands. The action commands will be used to determine which button
is selected. The radio buttons are grouped as described in Section 12.4. The 'up'-
button is selected. The class has only one method, getDirection . This returns
the direction specified by the currently selected button. The return value is the
corresponding direction-constant defined in class Constants .
×
File: its/BlockPuzzle/DirectionPanel.java
1. package its.BlockPuzzle;
2.
3. import java.awt.GridLayout;
4. import javax.swing.ButtonGroup;
5. import javax.swing.JPanel;
6. import javax.swing.JRadioButton;
7.
8.
9. public class DirectionPanel extends JPanel {
10.
private JRadioButton upBut, downBut, rBut, lBut;
11.
private ButtonGroup group;
12.
13.
public DirectionPanel(){
14.
this .setLayout( new GridLayout(4,1));
Search WWH ::




Custom Search