鼠标事件监听.txt
来自「该文件是用java开发工具编写的鼠标事件监听java源程序」· 文本 代码 · 共 56 行
TXT
56 行
import java.awt.*;
import java.awt.event.*;
public class Test extends Frame implements MouseMotionListener, MouseListener
{
TextField t=new TextField();
Test()
{
this.addMouseListener(this);
this.addMouseMotionListener(this);
this.add(t,BorderLayout.NORTH);
this.setSize(400,400);
this.setVisible(true);
}
public static void main(String args[])
{
Test my=new Test();
}
public void mouseDragged(MouseEvent e) {
t.setText("鼠标在拖拽 x="+e.getX()+" y="+e.getY());
}
public void mouseMoved(MouseEvent e) {
t.setText("鼠标在移动 x="+e.getX()+" y="+e.getY());
}
public void mouseClicked(MouseEvent e) {
t.setText("鼠标被点击一次");
}
public void mousePressed(MouseEvent e) {
t.setText("鼠标按键按下");
}
public void mouseReleased(MouseEvent e) {
t.setText("鼠标按键释放");
}
public void mouseEntered(MouseEvent e) {
t.setText("鼠标进入该区域");
this.setBackground(new Color((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256)));
}
public void mouseExited(MouseEvent e) {
t.setText("鼠标 离开该区域");
this.setBackground(new Color((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256)));
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?