Java Reference
In-Depth Information
The status panel has to display the number circles. We change class StatusPanel
from Chapter 6 as follows. We now use a 4
3 grid layout and three more labels.
The additional labels contain the text 'No. of circles', the number of circles, and
a dummy to fill the grid. We add a method setNoOfCircles(int n) to set the
number of circles.
×
File: its/InteractiveGraphic/StatusPanel.java
1. package its.InteractiveGraphic;
2.
3. import java.awt.GridLayout;
4. import javax.swing.JLabel;
5. import javax.swing.JPanel;
6.
7. public class StatusPanel extends JPanel
8. {
9.
private JLabel posText
= new JLabel("position:");
10.
private JLabel XCoord
= new JLabel("0", JLabel.RIGHT);
11.
private JLabel YCoord
= new JLabel("0", JLabel.RIGHT);
12.
private JLabel countText = new JLabel("no. of clicks");
13.
private JLabel counts
= new JLabel("0", JLabel.RIGHT);
14.
private JLabel dummy1
= new JLabel();
15.
private JLabel circleText = new JLabel("no. of circles");
16.
private JLabel noOfCirc
= new JLabel("0", JLabel.RIGHT);
17.
private JLabel dummy2
= new JLabel();
18.
private JLabel inOutText = new JLabel("mouse is in comp.");
19.
private JLabel inOut
= new JLabel("no", JLabel.RIGHT);
20.
private JLabel dummy3
= new JLabel();
21.
22.
private int clickCount = 0;
23.
24.
public StatusPanel()
{
25.
this .setLayout( new GridLayout(4,3));
26.
this .add(posText);
27.
this .add(XCoord);
28.
this .add(YCoord);
29.
this .add(countText);
30.
this .add(counts);
31.
this .add(dummy1);
32.
this .add(circleText);
33.
this .add(noOfCirc);
34.
this .add(dummy2);
35.
this .add(inOutText);
36.
this .add(inOut);
37.
this .add(dummy3);
38.
}
39.
Search WWH ::




Custom Search