participate


Abstract Window Toolkit (AWT) - Adding a custom cursor to a panel
<<   Back to Forum  |   Give us Feedback
10 Duke Stars rewarded for this thread
This topic has 4 replies on 1 page.
LukeARice
Posts:7
Registered: 10/18/04
Adding a custom cursor to a panel   
Oct 19, 2004 9:24 PM

 
HI, I am making a game where i want clicking a radio button to change the cursor image. I have figured out how to create a custom cursor, and even change the current cursor to it. The problem im having is i want to change it while the program is running. I can say somthing like frame.addCursor(cursor) but that sets it permenantly. What i would like is to add it to a panel during run-time. If anyone knows how i would go abou this i would be gratefull.

Thanks
 
BhavaniValivarthi
Posts:12
Registered: 2/26/04
Re: Adding a custom cursor to a panel   
Oct 20, 2004 4:48 AM (reply 1 of 4)  (In reply to original post )

 
Hope, this 'll help u..

if(radiobutton.getState())
{
setCursor(Toolkit.getDefaultToolkit().createCustomCursor(pointrimg, new Point(0, 0), "Pointer"));
//new Point(0,0) represents the hotspot..
}

else
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
 
LukeARice
Posts:7
Registered: 10/18/04
Re: Adding a custom cursor to a panel   
Oct 20, 2004 6:17 AM (reply 2 of 4)  (In reply to #1 )

 
Will this work as it is? Where can I put this, can i put this in the action performed of one of my panels? If this will work i thank you. But i cant try it out now but i will do so later.
 
BhavaniValivarthi
Posts:12
Registered: 2/26/04
Re: Adding a custom cursor to a panel      
Oct 20, 2004 11:43 PM (reply 3 of 4)  (In reply to #2 )

 
Do u mean, upon selecting the radio button, the cursor must be changed to the customized one?

If it is so,

u add the snippet in the itemStateChanged() event....of the radiobutton

i.e.,

public void itemStateChanged(ItemEvent ie)
{
if(ie.getStateChange() == ItemEvent.SELECTED)
{
myPanel.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(CursorImg, new Point
(0,0), "MyCursorImg"));

/
CursorImg - the image to display when the cursor is actived
new Point(0,0) - hotSpot
MyCursorImg - a localized description of the cursor, for Java Accessibility use
/

}
else
myPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
 
LukeARice
Posts:7
Registered: 10/18/04
Re: Adding a custom cursor to a panel   
Oct 21, 2004 12:03 PM (reply 4 of 4)  (In reply to #3 )

 
Wow your the man! I already did what you said before and i havent tried your latest post yet, but it looks like it works. I already did alot of what you just said but somthing was slightly off so your code helps. I shall be rewarding you ;-)
 
This topic has 4 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 28
  • Guests : 133

About Sun forums
  • Oracle Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Oracle Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums