import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CursorTest implements ItemListener
{
JPanel panel;
JComboBox cursors;
Cursor custom;
CursorTest()
{
panel = new JPanel();
panel.setPreferredSize(new Dimension(200,200));
//Create and load the duke icon.
ImageIcon icon = new ImageIcon("dukeWaveRed.gif");
custom = Toolkit.getDefaultToolkit().createCustomCursor(icon.getImage(), new Point(15,15),
"Duke Waving");
String names[] = new String[15];
int i;
for (i=0; i<20; i++) {
try {
names[i] = Cursor.getPredefinedCursor(i).getName();
}
catch(IllegalArgumentException e)
{
break;
}
}
System.out.println("There are " + i + " predefined cursors");
names[14] = custom.getName();
cursors = new JComboBox(names);
cursors.addItemListener(this);
JPanel top = new JPanel();
top.add(cursors);
JFrame frame = new JFrame("Cursor test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = frame.getContentPane();
c.add(panel);
c.add(top,BorderLayout.NORTH);
frame.pack();
frame.setVisible(true);
}
public void itemStateChanged(ItemEvent e)
{
int idx = cursors.getSelectedIndex();
panel.setCursor( idx<14? Cursor.getPredefinedCursor( idx ): custom );
}
public static void main(String args[])
{
new CursorTest();
}
}
Maintained by John Loomis, last updated 20 June 2000