import javax.swing.*;
import java.awt.event.*;
public class Test1 extends JFrame
{
public static void main(String[] args)
{
Test1 t = new Test1();
}
public Test1()
{
setSize(300,300);
this.getContentPane().addMouseListener(new mouseProcassor());
setVisible(true);
setLocationRelativeTo(null);
}
public class mouseProcassor extends MouseAdapter
{
public void mouseClicked(MouseEvent e)
{
String outStr = "";
if(e.getButton() == e.BUTTON1)
{
outStr = "左键";
}
else if(e.getButton() == e.BUTTON3)
{
outStr = "右键";
}
else
{
outStr = "中键";
}
if(e.getClickCount() == 2)
{
outStr = outStr + "双击";
}
else
{
outStr = outStr + "点击";
}
System.out.println(outStr);
}
}
}
用Java代码判断“左键点击”还是“右键点击”
最新推荐文章于 2021-03-16 14:57:19 发布