import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/** Program to demonstrate using context-sensitive cursors.<p>
*
* Screen snaps:<p>
*
* <code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Standard cursor...</code><br>
* <center><img src="DemoCursorControl-1.gif"></center><p>
* 
* <code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Hand cursor...</code><br>
* <center><img src="DemoCursorControl-2.gif"></center><p>
* 
* <code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Wait cursor...</code><br>
* <center><img src="DemoCursorControl-3.gif"></center><p>
* 
* <code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Crosshair cursor...</code><br>
* <center><img src="DemoCursorControl-4.gif"></center><p>
* 
* @see <a href="DemoCursorControl.java">source code</a>
* @author Scott MacKenzie, 2002
*/
public class DemoCursorControl
{
   public static void main(String[] args)
   {
      DemoCursorControlFrame frame = new DemoCursorControlFrame();
      frame.setTitle("DemoCursorControl");
      frame.pack();
      frame.show();
   }
}

class DemoCursorControlFrame extends JFrame implements ActionListener 
{
   private JButton button1;
   private JButton button2;
   private JButton button3;
   private JButton button4;

   // constructor
   public DemoCursorControlFrame()
   {
      // -------------------------------
      // create and configure components
      // -------------------------------

      button1 = new JButton("Standard");
      button2 = new JButton("Hand");
      button3 = new JButton("Wait");
      button4 = new JButton("Crosshair");

      // setup special cursors

      button2.setCursor(new Cursor(Cursor.HAND_CURSOR));
      button3.setCursor(new Cursor(Cursor.WAIT_CURSOR));
      button4.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));

      // -------------
      // add listeners
      // -------------

      button1.addActionListener(this);
      button2.addActionListener(this);
      button3.addActionListener(this);
      button4.addActionListener(this);
      this.addWindowListener(new WindowCloser());

      // ------------------
      // arrange components
      // ------------------

      // put components in panels

      JPanel panel = new JPanel();
      panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
      panel.setLayout(new GridLayout(1, 4, 10, 0));
      panel.add(button1);
      panel.add(button2);
      panel.add(button3);
      panel.add(button4);

      // create a container for this (extended) JFrame's content pane

      Container contentPane = this.getContentPane();

      //  add panels to the container

      contentPane.add(panel, "Center");
   }

   // -------------------------------
   // implement ActionListener method
   // -------------------------------

   public void actionPerformed(ActionEvent ae)
   {
      System.exit(0);   
   }

   // -----------
   // inner class
   // -----------

   // Note: WindowAdapter implements WindowListener

   private class WindowCloser extends WindowAdapter
   {
      public void windowClosing(WindowEvent event)
      {
         System.exit(0);
      }
   }
}

