文件名称:mousetrack
介绍说明--下载内容均来自于网络,请自行研究使用
知识点:使用Graphics类制作方块,使用java.awt.Event类响应鼠标动作,使用Color类设置方块的颜色,使用int类记录光标的位置。
实现思路:首先要制作界面中的方块,通过Graphics类的对象函数g.setColor(Color.red)设置方块的颜色为红色,然后通过语句g.drawRect(0, 0, size().width - 1, size().height - 1)和g.drawRect(mx, my, (size().width/10) - 1, (size().height/10) - 1)绘制出两个矩形,完成方块的制作。然后实现“抓不住的方块”效果,要响应鼠标事件,通过函数public boolean mouseDown(java.awt.Event evt, int x, int y响应按下鼠标的动作,通过光标位置的判断来避免鼠标抓到界面中的方块-Knowledge: Use the Graphics class production box, use java.awt.Event class response to mouse movements, using color Color class settings box, use the cursor position int class record.
Realization of ideas: First, to make the interface box, set the box through the Graphics class object function g.setColor (Color.red) color is red, then the statement g.drawRect (0, 0, size () width- 1. , size () height-. 1) and g.drawRect (mx, my, (size () .width/10)- 1, (size () .height/10)- 1) draw two rectangles, complete the box production. Then realize "box not catch" effect, to respond to mouse events, through the function public boolean mouseDown (java.awt.Event evt, int x, int y action in response to pressing the mouse, by judging the mouse cursor position to avoid grasping the interface box
实现思路:首先要制作界面中的方块,通过Graphics类的对象函数g.setColor(Color.red)设置方块的颜色为红色,然后通过语句g.drawRect(0, 0, size().width - 1, size().height - 1)和g.drawRect(mx, my, (size().width/10) - 1, (size().height/10) - 1)绘制出两个矩形,完成方块的制作。然后实现“抓不住的方块”效果,要响应鼠标事件,通过函数public boolean mouseDown(java.awt.Event evt, int x, int y响应按下鼠标的动作,通过光标位置的判断来避免鼠标抓到界面中的方块-Knowledge: Use the Graphics class production box, use java.awt.Event class response to mouse movements, using color Color class settings box, use the cursor position int class record.
Realization of ideas: First, to make the interface box, set the box through the Graphics class object function g.setColor (Color.red) color is red, then the statement g.drawRect (0, 0, size () width- 1. , size () height-. 1) and g.drawRect (mx, my, (size () .width/10)- 1, (size () .height/10)- 1) draw two rectangles, complete the box production. Then realize "box not catch" effect, to respond to mouse events, through the function public boolean mouseDown (java.awt.Event evt, int x, int y action in response to pressing the mouse, by judging the mouse cursor position to avoid grasping the interface box
(系统自动生成,下载前可以参看下载内容)
下载文件列表
Java抓不住的方块\MouseTrack.class
................\MouseTrack.html
................\MouseTrack.java
................\_desktop.ini
................\抓不住的方块.doc
Java抓不住的方块