Java Reference
In-Depth Information
File:
its/MouseEvents/StatusPanel.java
package
its.MouseEvents;
1.
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 inOutText =
new
JLabel("mouse is in comp.");
16.
private
JLabel inOut
=
new
JLabel("no", JLabel.RIGHT);
17.
private
JLabel dummy2
=
new
JLabel();
18.
private int
clickCount = 0;
19.
20.
public
StatusPanel()
{
21.
this
.setLayout(
new
GridLayout(3,3));
22.
this
.add(posText);
23.
this
.add(XCoord);
24.
this
.add(YCoord);
25.
this
.add(countText);
26.
27.
this
.add(counts);
28.
this
.add(dummy1);
29.
this
.add(inOutText);
30.
this
.add(inOut);
31.
this
.add(dummy2);
32.
}
33.
//
Updates the displayed coordinates of the mouse position.
34.
public void
setCoordinates(
int
x,
int
y)
35.
{
36.
XCoord.setText(Integer.toString(x));
37.
YCoord.setText(Integer.toString(y));
38.
}
39.
//
Sets the information whether the mouse is in or out.
40.
public void
setInOut(String str)
{
41.
inOut.setText(str);
42.
}
43.
//
Increments the click count and displays it.
44.
Search WWH ::
Custom Search