文件名称:97
介绍说明--下载内容均来自于网络,请自行研究使用
编程思路:首先,本练习因为要制作抓不住的方块的实例,所以首先要制作界面中的方块,先通过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响应按下鼠标的动作,通过光标位置的判断来避免鼠标抓到界面中的方块。-Programming ideas: first, to make this exercise because the instance box not catch, so first of all to make the interface box, first set the box through the Graphics class object function g.setColor (Color.red) color is red, then By 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, thus completing the box production. Then, in order to achieve " catch box" effect, so to respond to mouse events, through the function public boolean mouseDown (java.awt.Event evt, int x, int y in response to pressing the mouse moves the cursor position to judge by Avoid mouse caught in the interface box.
(系统自动生成,下载前可以参看下载内容)
下载文件列表
练习97抓不住的方块\MouseTrack.class
..................\MouseTrack.html
..................\MouseTrack.java
..................\_desktop.ini
..................\练习96抓不住的方块.doc
练习97抓不住的方块