-----------------------------------------------------------------------------------
걍.. 쓸 일도 있고.. 심심하기도 해서 끄적여 만들어본 예제 코드...
-----------------------------------------------------------------------------------
// Ver. Frame
import java.awt.*;
import javax.swing.*;
public class Main extends JFrame
{
private Cursor cursor = null;
public Main()
{
super("사용자 정의 커서");
init();
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(400, 300);
setVisible(true);
}
private void init()
{
Toolkit toolkit = Toolkit.getDefaultToolkit();
MediaTracker tracker = new MediaTracker(this);
Image cursorImage = toolkit.getImage("./bin/images/i_mouse.png");
tracker.addImage(cursorImage, 0);
try { tracker.waitForID(0); }
catch (InterruptedException ie) { ie.printStackTrace(); }
try
{
Point hotSpot = new Point(1, 1);
cursor = toolkit.createCustomCursor(cursorImage, hotSpot, "i_mouse Cursor");
if(cursor != null)
{
setCursor(cursor);
}
}
catch (IndexOutOfBoundsException e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
new Main();
}
}
// Ver. Applet
import java.awt.*;
import java.applet.*;
public class Main extends Applet!!
{
private Cursor cursor = null;
public void init()
{
// load the image with the Media Tracker
MediaTracker tracker = new MediaTracker(this);
Image cursorImage = getImage(getCodeBase(), "images/i_mouse.png");
tracker.addImage(cursorImage, 0);
try { tracker.waitForID(0); }
catch (InterruptedException ie)
{
ie.printStackTrace();
}
// get the toolkit for this environment
Toolkit tookit = getToolkit();
try
{
// this is the x,y coordinates of the image which will actually do the "clicking"
Point hotSpot = new Point(1, 1);
// create the custom cursor
cursor = tookit.createCustomCursor(cursorImage, hotSpot, "i_mouse Cursor");
}
catch (IndexOutOfBoundsException e)
{
e.printStackTrace();
}
// set the cursor for this applet!! component
setCursor(cursor);
}
}
-----------------------------------------------------------------------------------
'IT_Programming > Java' 카테고리의 다른 글
[펌] Java AWT:Lightweight UI Framework (0) | 2010.10.08 |
---|---|
[펌] JNI - Package 안에서 JNI 사용하기 (JNI IN PACKAGE) (0) | 2010.09.29 |
[펌] 이미지 크기 변환할 때 품질 유지하기 (0) | 2010.09.06 |
[펌] Java Concurrency: Executor와 Callable/Future (0) | 2010.09.06 |
[펌] ThreadLocal 사용법과 활용 (0) | 2010.09.06 |