static int CROSSHAIR_CURSOR 十字光标类型。 static int DEFAULT_CURSOR 默认光标类型(如果没有定义光标,则获取该设置)。 static int E_RESIZE_CURSOR 调整窗口右边框大小的光标类型。(左右箭头型) static int HAND_CURSOR 手状光标类型。 static int MOVE_CURSOR 移动光标类型。 static int N_RESIZE_CURSOR 调整窗口上边框大小的光标类型。(上下箭头型)
static int NE_RESIZE_CURSOR 调整窗口右上角大小的光标类型。 (45°斜箭头型) static int NW_RESIZE_CURSOR 调整窗口左上角大小的光标类型。(135°斜箭头型) static int S_RESIZE_CURSOR 调整窗口下边框大小的光标类型。 (上下箭头) static int SE_RESIZE_CURSOR 调整窗口右下角大小的光标类型。(135°斜箭头型) static int SW_RESIZE_CURSOR 调整窗口左下角大小的光标类型。 (45°斜箭头型) static int TEXT_CURSOR 文字光标类型。 static int W_RESIZE_CURSOR (左右箭头) 调整窗口左边框大小的光标类型。 static int WAIT_CURSOR 等待光标类型。
import java.awt.*;public class CursorTest extends Frame { public CursorTest() { Button button = new Button("Click"); button.setCursor(new Cursor(Cursor.NE_RESIZE_CURSOR)); button.setCursor(createCursor()); add(button); setVisible(true); setSize(400,400); } public static Cursor createCursor() { String fileName = "apple_red.png"; Image cursor = Toolkit.getDefaultToolkit().createImage(fileName); return Toolkit.getDefaultToolkit().createCustomCursor(cursor,new Point(10,10),"newCursor"); } public static void main(String[] args) { new CursorTest(); } }
public Cursor createCursor(){
Image MyCursor1 = getImage(getDocumentBase(),"Images/hammer1.gif");
try{
mt=new MediaTracker(this);
mt.addImage(img,0);
mt.waitForAll();
return Toolkit.getDefaultToolkit().createCustomCursor(MyCursor1,new Point(0,0),"invisi");
}catch(Exception e){
}
return null;
}
一个button调用:
Cursor cu= createCursor(); //该按钮使用定制的鼠标
button.setCursor(cu);
十字光标类型。
static int DEFAULT_CURSOR
默认光标类型(如果没有定义光标,则获取该设置)。
static int E_RESIZE_CURSOR
调整窗口右边框大小的光标类型。(左右箭头型)
static int HAND_CURSOR
手状光标类型。
static int MOVE_CURSOR
移动光标类型。
static int N_RESIZE_CURSOR
调整窗口上边框大小的光标类型。(上下箭头型)
static int NE_RESIZE_CURSOR
调整窗口右上角大小的光标类型。 (45°斜箭头型)
static int NW_RESIZE_CURSOR
调整窗口左上角大小的光标类型。(135°斜箭头型)
static int S_RESIZE_CURSOR
调整窗口下边框大小的光标类型。 (上下箭头)
static int SE_RESIZE_CURSOR
调整窗口右下角大小的光标类型。(135°斜箭头型)
static int SW_RESIZE_CURSOR
调整窗口左下角大小的光标类型。 (45°斜箭头型)
static int TEXT_CURSOR
文字光标类型。
static int W_RESIZE_CURSOR (左右箭头)
调整窗口左边框大小的光标类型。
static int WAIT_CURSOR
等待光标类型。
import java.awt.*;public class CursorTest extends Frame
{
public CursorTest()
{
Button button = new Button("Click");
button.setCursor(new Cursor(Cursor.NE_RESIZE_CURSOR));
button.setCursor(createCursor());
add(button);
setVisible(true);
setSize(400,400);
}
public static Cursor createCursor()
{
String fileName = "apple_red.png";
Image cursor = Toolkit.getDefaultToolkit().createImage(fileName);
return Toolkit.getDefaultToolkit().createCustomCursor(cursor,new Point(10,10),"newCursor");
}
public static void main(String[] args)
{
new CursorTest();
}
}