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);
}
}
}
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 Swing应用程序,该程序演示了如何使用MouseListener监听鼠标点击事件,并根据鼠标按钮及点击次数输出相应的信息。
443

被折叠的 条评论
为什么被折叠?



