import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/** DemoCursorControl - program to demonstrate using context-sensitive
* cursors.<p>
*
* Screen snaps:<p>
*
* <center><img src="DemoCursorControl-1.gif"></center><p>
* 
* 
* @see <a href="DemoCursorControl.java">source code</a>
* @author Scott MacKenzie, 2003
*/
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;
   private JButton button5;


   // constructor
   public DemoCursorControlFrame()
   {
      // -------------------------------
      // create and configure components
      // -------------------------------

      button1 = new JButton("Standard");
      button2 = new JButton("Hand");
      button3 = new JButton("Wait");
      button4 = new JButton("Crosshair");
		button5 = new JButton("Box");

      // setup special cursors

      button2.setCursor(new Cursor(Cursor.HAND_CURSOR));
      button3.setCursor(new Cursor(Cursor.WAIT_CURSOR));
      button4.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));

		// including a custom cursor...

		Image boxCursor = new ImageIcon("cursor-box.gif").getImage();
		int x = boxCursor.getWidth(this) / 2 + 1;
		int y = boxCursor.getHeight(this) / 2 + 1;
		Point center = new Point(x, y);
		Toolkit t = Toolkit.getDefaultToolkit();
		Cursor c = t.createCustomCursor(boxCursor, center, "box");
      button5.setCursor(c);

      // -------------
      // add listeners
      // -------------

      button1.addActionListener(this);
      button2.addActionListener(this);
      button3.addActionListener(this);
      button4.addActionListener(this);
      button5.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, 5, 10, 0));
      panel.add(button1);
      panel.add(button2);
      panel.add(button3);
      panel.add(button4);
      panel.add(button5);

      // 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);
      }
   }
}

