Get Click Count Mouse Listener on Touch Screen

ぐ巨炮叔叔 提交于 2019-12-08 08:06:25

问题


Im running a simple JFrame with a JList.

I encountered an issue just like this guy> Java getClickCount on touchscreen

I know it has been posted already but there were no answers.

jList.addMouseListener(new MouseAdapter() {
         public void mouseClicked(MouseEvent e) {   
             System.out.println("MouseClick: "+e.getClickCount());
             if (e.getClickCount() == 2) {

回答1:


Code below is working..

public class MainTest extends JPanel {

 public MainTest() {

      addMouseListener(new MouseAdapter() { 
          public void mousePressed(MouseEvent me) { 
            System.out.println(me.getClickCount()); 
          } 
        }); 

  }

  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.getContentPane().add(new MainTest());

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setSize(200, 200);
    frame.setVisible(true);
  }

}



来源:https://stackoverflow.com/questions/37923323/java-getclickcount-on-touchscreen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!