Java Reference
In-Depth Information
31
int xPos = event.getX(); // get x-position of mouse
32
int yPos = event.getY(); // get y-position of mouse
33
34
details = String.format( "Clicked %d time(s)" ,
35
event.getClickCount()
);
36
37
if (
event.isMetaDown()
) // right mouse button
38
details += " with right mouse button" ;
39
else if (
event.isAltDown()
) // middle mouse button
40
details += " with center mouse button" ;
41
else // left mouse button
42
details += " with left mouse button" ;
43
44
statusBar.setText(details); // display message in statusBar
45
}
46
}
47
} // end class MouseDetailsFrame
Fig. 12.31 | Demonstrating mouse clicks and distinguishing between mouse buttons. (Part 2 of 2.)
1
// Fig. 12.32: MouseDetails.java
2
// Testing MouseDetailsFrame.
3
import javax.swing.JFrame;
4
5
public class MouseDetails
6
{
7
public static void main(String[] args)
8
{
9
MouseDetailsFrame mouseDetailsFrame = new MouseDetailsFrame();
10
mouseDetailsFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
11
mouseDetailsFrame.setSize( 400 , 150 );
12
mouseDetailsFrame.setVisible( true );
13
}
14
} // end class MouseDetails
Fig. 12.32 | Testing MouseDetailsFrame .
Search WWH ::




Custom Search