JimmySavel
Pun King
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 2
900 XP
In this tutorial, we will create a program that will change the default cursor into a hand cursor in java like the image below.
So, now let's start this tutorial!
1. Open JCreator or NetBeans and make a java program with a file name of jCursor.java.
2. Import java.io package. Hence the cursor class is in the input/output library. Import also javax.swing package because we will use JFrame and setCursor method here in the frame.
3. In your class name make it sure it extends JFrame.
4. Now, create a constructor that is the same with the file name.
Create an instance of a Cursor class with a variable cursor and set it into Hand Cursor.
For window characteristics:
5. In your Main, create a JFrame component that will hold all components. This will set the visibility to True, set the size, location, and has the title of the program.
Press F5 to run the program.
Full source code:
Hope this helps! :)
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
If you have some queries, feel free to contact the number or e-mail below.
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware
Download

So, now let's start this tutorial!
1. Open JCreator or NetBeans and make a java program with a file name of jCursor.java.
2. Import java.io package. Hence the cursor class is in the input/output library. Import also javax.swing package because we will use JFrame and setCursor method here in the frame.
- import
javax.swing.*
;
- import
java.awt.*
;
3. In your class name make it sure it extends JFrame.
- public
class
jCursor extends
JFrame
{
4. Now, create a constructor that is the same with the file name.
- public
jCursor(
)
{
Create an instance of a Cursor class with a variable cursor and set it into Hand Cursor.
For window characteristics:
- this
.setDefaultCloseOperation
(
JFrame
.EXIT_ON_CLOSE
)
;
- this
.pack
(
)
;
5. In your Main, create a JFrame component that will hold all components. This will set the visibility to True, set the size, location, and has the title of the program.
- public
static
void
main(
String
[
]
args)
{
- JFrame
cur =
new
jCursor(
)
;
- cur.setTitle
(
"Hand Cursor"
)
;
- cur.setVisible
(
true
)
;
- cur.setSize
(
300
,250
)
;
- cur.setLocation
(
250
,300
)
;
- }
Press F5 to run the program.
Full source code:
- import
javax.swing.*
;
- import
java.awt.*
;
- public
class
jCursor extends
JFrame
{
- public
jCursor(
)
{
- Cursor
cursor =
new
Cursor
(
Cursor
.HAND_CURSOR
)
;
- this
.setCursor
(
cursor)
;
- this
.setDefaultCloseOperation
(
JFrame
.EXIT_ON_CLOSE
)
;
- this
.pack
(
)
;
- }
- public
static
void
main(
String
[
]
args)
{
- JFrame
cur =
new
jCursor(
)
;
- cur.setTitle
(
"Hand Cursor"
)
;
- cur.setVisible
(
true
)
;
- cur.setSize
(
300
,250
)
;
- cur.setLocation
(
250
,300
)
;
- }
- }
Hope this helps! :)
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
If you have some queries, feel free to contact the number or e-mail below.
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware
Download
You must reply in the thread to view hidden content. Upgrade your account to always see hidden content.