Changing the mouse pointer to a hand cursor when the mouse moves over a JButton

Main.java:

import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
 
public class Main extends JFrame
{
   private Cursor handCursor = new Cursor(Cursor.HAND_CURSOR);
   private Cursor defaultCursor = new Cursor(Cursor.DEFAULT_CURSOR);
 
   public static void main(String []args) {
      Main main = new Main();
      main.show();
   }
 
   public Main() {
      JButton button = new JButton("Move mouse over this button!");
      button.addMouseListener(new MouseAdapter() {
         public void mouseEntered(MouseEvent me) {
            setCursor(handCursor);
         }
         public void mouseExited(MouseEvent me) {
            setCursor(defaultCursor);
         }
      });
  
      getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER));
      getContentPane().add(button);
 
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
            System.exit(0);
         }
      });
 
      setSize(300, 100);
   }  
}