⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 鼠标事件监听.txt

📁 该文件是用java开发工具编写的鼠标事件监听java源程序
💻 TXT
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -