简体   繁体   中英

How do I determine if the left or right mouse button was clicked in Java?

I am trying to make a program in Java that uses both the left and right mouse buttons. The default MouseMotionListener and MouseListener trigger for both mouse clicks.

Is any way to determine what button is clicked?

Use the method getButton()

It returns 1 for leftClick and 3 for rightClick .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM