Java:为什么左键单击按钮比右键更快

时间:2016-12-17 08:43:22

标签: java mouselistener right-click

您好我做了一个简单的例子。如果我点击右击更快似乎没有左键单击鼠标的响应...为什么?

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JButton;
import javax.swing.JFrame;

class MouseHandler implements MouseListener{

@Override
public void mouseClicked(MouseEvent e) {
    // TODO Auto-generated method stub
    if(e.getButton()==MouseEvent.BUTTON1){
        System.out.println("ssssssss");
    }
    if(e.getButton()==MouseEvent.BUTTON3){
        System.out.println("dddddd");
    }

}

@Override
public void mousePressed(MouseEvent e) {
    // TODO Auto-generated method stub

}

@Override
public void mouseReleased(MouseEvent e) {
    // TODO Auto-generated method stub

}

@Override
public void mouseEntered(MouseEvent e) {
    // TODO Auto-generated method stub

}

@Override
public void mouseExited(MouseEvent e) {
    // TODO Auto-generated method stub

}

}

public class PratoUI {
JButton b[][];
public PratoUI(){
    JFrame finestra = new JFrame();
    finestra.setLayout(null);
    finestra.setSize(500,300);
    finestra.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JButton b=new JButton("vvv");
    b.setBounds(0,0,60,60);
    b.addMouseListener(new MouseHandler());
    finestra.add(b);

    finestra.setVisible(true);
}

public static void main(String[] args) {
    // TODO Auto-generated method stub
    new PratoUI();
}

}

0 个答案:

没有答案