Using Custom Cursors in Java!

Java Discuss, Using Custom Cursors in Java! at Programmers Lounge forum; Credits: Kevin Long This tutorial shows how to go beyond the predefined cursors in Java and create your own cursors ...


Go Back   Gamerz Needs - For All Your Gaming Needs! > Technology Zone > Programmers Lounge > Java
Forgot Password? | Sign Up!

Notices

Advertisement
   

Closed Thread
 
Bookmark this Thread Tools Display Modes
  #1  
Old 07-22-2006, 02:40 AM
M0NK3Y's Avatar
Armenia
 
Last Online: Today 01:41 PM
Join Date: Mar 2006
Location: Boss World :D
Posts: 2,671
Thanks: 225
Thanked 540 Times in 348 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 14
M0NK3Y will become famous soon enough
Points: 43,664.01
Bank: 499.61
Total Points: 44,163.62
Banana *yey* i <3 banana milkshake - Demonite cuz you back again lol - GameLordquest wanne do it again? xD - DeathniteR AYE AYE PIRATE! DRINK YOUR BEERZ! - M0NK3Y Im a M0NK3Y Pirate so.. i need a banana! :D - M0NK3Y 
No Message - M0NK3Y No Message - M0NK3Y No Message - M0NK3Y No Message - M0NK3Y 
Black - Andrex2x Burgundy - Demonite Black - Demonite Burgundy - Demonite 
Send a message via ICQ to M0NK3Y Send a message via AIM to M0NK3Y Send a message via MSN to M0NK3Y Send a message via Yahoo to M0NK3Y
Using Custom Cursors in Java!

Credits: Kevin Long
This tutorial shows how to go beyond the predefined cursors in Java and create your own cursors using a GIF or PNG that are dsiplayed when the user moves the mouse over a Java component (AWT or Swing).

Creating the Cursor Image
For the custom cursor, a transparent GIF or PNG will be needed for the cursor. For this tutorial, a sample transparent GIF image of a pencil is provided below (right click to save):

'


Loading the Cursor Image
The image for the custom cursor needs to be loaded into an Image object.

//Get the default toolkit
Toolkit toolkit = Toolkit.getDefaultToolkit();

//Load an image for the cursor
Image cursorImage = toolkit.getImage("pencil.gif");
Defining the Cursor Hot Spot
The cursor hot spot is used for the point location in mouse events. For a cursor such as a cross-hair cursor, the hot spot would be in the center of the cursor. In our example, the cursor hot spot will be at the pencil point or the point 0,0.

//Create the hotspot for the cursor
Point cursorHotSpot = new Point(0,0);
Creating the Custom Cursor
To create the custom image, we put together the cursor image and the hot spot:

//Create the custom cursor
Cursor customCursor = toolkit.createCustomCursor(cursorImage, cursorHotSpot, "Pencil");
Displaying the Custom Cursor
The final step is to notify the component to display the cursor.

//Use the custom cursor
setCursor(customCursor);
__________________
The Following 3 Users Say Thank You to M0NK3Y For This Useful Post:
dragoon (07-23-2006), Faulrn (08-20-2006), M4G3 (10-30-2007)
  #2  
Old 08-20-2006, 06:10 PM
Stone Axe
 
Last Online: 09-10-2008 12:42 AM
Join Date: Dec 2005
Age: 20
Posts: 37
Thanks: 2
Thanked 3 Times in 3 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 0
Faulrn is an unknown quantity at this point
Points: 1,407.15
Bank: 956.90
Total Points: 2,364.05
Now this is something useful, considering ill be goin to java class in 20 mins.

thx for this. Thx for sure.
  #3  
Old 08-23-2006, 09:37 AM
M0NK3Y's Avatar
Armenia
 
Last Online: Today 01:41 PM
Join Date: Mar 2006
Location: Boss World :D
Posts: 2,671
Thanks: 225
Thanked 540 Times in 348 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 14
M0NK3Y will become famous soon enough
Points: 43,664.01
Bank: 499.61
Total Points: 44,163.62
Banana *yey* i <3 banana milkshake - Demonite cuz you back again lol - GameLordquest wanne do it again? xD - DeathniteR AYE AYE PIRATE! DRINK YOUR BEERZ! - M0NK3Y Im a M0NK3Y Pirate so.. i need a banana! :D - M0NK3Y 
No Message - M0NK3Y No Message - M0NK3Y No Message - M0NK3Y No Message - M0NK3Y 
Black - Andrex2x Burgundy - Demonite Black - Demonite Burgundy - Demonite 
Send a message via ICQ to M0NK3Y Send a message via AIM to M0NK3Y Send a message via MSN to M0NK3Y Send a message via Yahoo to M0NK3Y
xD No Problem!!!
__________________
  #4  
Old 08-23-2006, 05:11 PM
Stone Axe
 
Last Online: 09-10-2008 12:42 AM
Join Date: Dec 2005
Age: 20
Posts: 37
Thanks: 2
Thanked 3 Times in 3 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 0
Faulrn is an unknown quantity at this point
Points: 1,407.15
Bank: 956.90
Total Points: 2,364.05
btw you might have messd up something. The last statement gives me an error.

I can't remember the exact erro now but it was somethign about not finding the method.

I can see no methd and i can see you are trying to call a method. How is that possible?
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Advertisement
   


Main Navigation
Home
GzN Forums
GzN Games
GzN News
Top Games
GzN Cheats
GzN Articles
GzN Reviews
GzN Downloads
User Control Panel
Advertising
RSS Feed
2Moons
Adventure Quest
AirRivals
America's Army
Anarchy Online
Archlord
Audition
Battlefield Series
Cabal Online
Call Of Duty Series
Combat Arms
Conquer Online
Counter Strike
Day of Defeat
Deicide Online
Diablo Series
Doom Series
Drift City
Enemy Territory
Eudemons Online
Final Fantasy
Flyff (Fly For Fun)
FreeStyle Street Basketball
General Game Discussion
Ghost Online
Granado Espada
Grand Theft Auto Series
Guild Wars
Gunbound
Gunz Online
Habbo Hotel
Half-Life 2
Hero Online
KartRider
Knights Online
Maple Story
Medal of Honor
MU Online
Neopets
Pangya
Quake Series
Ragnarok Online
Rappelz
Rakion
Red Orchestra
Rose Online
Runescape
Scions of Fate
Silkroad Online
Sims Series
Soldier Front
Starcraft
Tales of Pirates
Tibia
The Ship
Trickster Online
TS Online
Unreal Tournament
War Rock
WolfTeam
World of Warcraft & Series
Affiliates
COD4 Hacks
BF2 Hacks


All times are GMT -8. The time now is 02:40 PM.