Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cursor question

Status
Not open for further replies.

ToddR

Programmer
Feb 28, 2001
35
0
0
US
I am brand spankin' new to Java. Trying to set a cursor but having no luck.

import javax.swing.*;
import java.awt.*;

JButton j = new JButton("Press me");
j.setCursor(HAND_CURSOR);

Also tried:
JButton j = new JButton("Hi");
Cursor cr = new Cursor(HAND_CURSOR);
j.setCursor(cr);

I keep getting "cannot resolve symbol HAND_CURSOR". I've tried importing java.awt.cursor, still with no luck.

Thanks for helping a newbie!

 
I figured it out.

In case you're reading this because you are also new to Java, try this:

JButton j = new JButton("Press me");
j.setCursor(Cursor.setPredefinedCursor(Cursor.HAND_CURSOR));

 
ToddR,<br><br>You're correct. HAND_CURSOR is a variable inside of the &quot;Cursor&quot; class. It's called a &quot;public field&quot;; public because any object can access it, and a field because, well, it's not a method. (short and sweet definition of 'field', although not great by any means.) It's also &quot;static&quot;, meaning it can be run without having to create an instance of the class, as there is only one copy in existence. When using a static class variable, you'll always have that format: ClassName.FIELD_NAME. You can't leave the class name out, or else it won't know in which class to look. (Importing packages only gives the java compiler the ability to know which classes it can see, but it doesn't tell you which one you're talking about at the moment.)<br><br>Best of luck when programming in the future, and don't hesitate to ask any questions on the forum. <p>Liam Morley<br><A HREF="mailto:"></A><br>&quot;light the deep, and bring silence to the world.<br>light the world, and bring depth to the silence.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top