moused.java

来自「java的事件处理之关于鼠标!」· Java 代码 · 共 79 行

JAVA
79
字号
/*
// header - edit "Data/yourJavaAppletHeader" to customize
// contents - edit "EventHandlers/Java Applet/onCreate" to customize
*/
import java.awt.*;
import java.applet.Applet;
public class moused extends Applet
{
	int mouse_x,mouse_y;
	String s;
	public void init()
	{
		resize(300,300);
	}
	//public boolean handleEvent(Event evt)
	//{
		//return true;
	//}
	public boolean action(Event evt,Object o)
	{
	return true;
	}
	public boolean mouseDown(Event evt,int x,int y)
	{
		mouse_x=x;
		mouse_y=y;
		s="mouseDown:";
		repaint();
	return true;
	}
	public boolean mouseUp(Event evt,int x,int y)
	{
		mouse_x=x;
		mouse_y=y;
		s="mouseUp:";
		repaint();
		return true;
	}
	public boolean mouseEnter(Event evt,int x,int y)
	{
		mouse_x=100;
		mouse_y=100;
		s="mouseEnter:";
		
		repaint();
		return true;
	}
	public boolean mouseExit(Event evt,int x,int y)
	{
		mouse_x=50;
		mouse_y=50;
		s="mouseExit:";
		repaint();
		return true;
	}
	public boolean mouseDrag(Event evt,int x,int y)
	{
		mouse_x=x;
		mouse_y=y;
		s="mouseDrag:";
		repaint();
		return true;
	}
	//public boolean mouseMove(Event evt,int x,int y)
	//{
		//mouse_x=x;
		//mouse_y=y;
		//s="mouseMove:";
		//repaint();
		//return true;
	//}
  
	public void paint(Graphics g)
	{
		g.drawString(s, mouse_x, mouse_y);
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?