Java Swing mouse Double-click and right key event handling

Source: Internet
Author: User

public class Mymouselistener extends Mouseadapter {
public void mouseclicked (MouseEvent evt) {
if (evt.getclickcount () = = 3) {
Handle mouse three Hits
else if (evt.getclickcount () = = 2) {
Handle mouse Double-click
}
}
}

Working with the right mouse button

Public mouseclicked (MouseEvent e) {

if (E.ismetadown ()) {//Detect the right mouse button click

}

How to handle the middle mouse button in a small program.

New Mymouselistener ());

public class Mymouselistener extends Mouseadapter {
public void mouseclicked (MouseEvent evt) {
if (Evt.getmodifiers ().
Inputevent.button1_mask)!= 0) {
Processleft (Evt.getpoint ());
Working with the left mouse button click
}
if (Evt.getmodifiers ().
Inputevent.button2_mask)!= 0) {
Processmiddle (Evt.getpoint ());
Handle the middle mouse button click
}
if (Evt.getmodifiers ().
Inputevent.button3_mask)!= 0) {
Processright (Evt.getpoint ());
Working with the right mouse button click

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.