A Cursor is a subclass of Object class and it can be defined as point or indicator on the screen. A Cursor is used to select the input from the system that the user operates with the mouse. Different types of cursors available in the Cursor class are DEFAULT_CURSOR, CROSSHAIR_CURSOR, HAND_CURSOR, TEXT_CURSOR, WAIT_CURSOR and etc. The important methods of Cursor class are getDefaultCursor(), getName(), getPredefinedCursor(), getSystemCustomCursor() and getType().
Example
import java.awt.*;
import javax.swing.*;
public class CursorTest extends JFrame {
public CursorTest() {
setTitle("Cursor Test");
Cursor cursor = new Cursor(Cursor.HAND_CURSOR); // HAND CURSOR
setCursor(cursor);
setSize(375, 250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] args) {
new CursorTest();
}
}Output
