Change Default Cursor to Hand Cursor in Java
Submitted by donbermoy on Thursday, May 29, 2014 - 18:55.
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.
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
- import javax.swing.*;
- import java.awt.*;
- public jCursor() {
- this.pack();
Press F5 to run the program.
Full source code:
- import javax.swing.*;
- import java.awt.*;
- public jCursor() {
- this.setCursor(cursor);
- this.pack();
- }
- cur.setTitle("Hand Cursor");
- cur.setVisible(true);
- cur.setSize(300,250);
- cur.setLocation(250,300);
- }
- }
Add new comment
- 130 views