Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Java Programming Code Examples

Java > Other Code Examples

Changing mouse pointer

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
Changing mouse pointer package com.ack.gui.awt.simple; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class ChangingMousePointer implements ActionListener { private Frame f; private Button b; private String[] cursorPointerStringArray = { "Cursor.CROSSHAIR_CURSOR", "Cursor.DEFAULT_CURSOR", "Cursor.HAND_CURSOR", "Cursor.MOVE_CURSOR", "Cursor.TEXT_CURSOR", "Cursor.WAIT_CURSOR", "Cursor.E_RESIZE_CURSOR", "Cursor.NE_RESIZE_CURSOR", "Cursor.NW_RESIZE_CURSOR", "Cursor.NW_RESIZE_CURSOR", "Cursor.N_RESIZE_CURSOR", "Cursor.SE_RESIZE_CURSOR", "Cursor.SW_RESIZE_CURSOR", "Cursor.SW_RESIZE_CURSOR", "Cursor.S_RESIZE_CURSOR", "Cursor.W_RESIZE_CURSOR"}; private int[] cursorPointerArray = { Cursor.CROSSHAIR_CURSOR, Cursor.DEFAULT_CURSOR, Cursor.HAND_CURSOR, Cursor.MOVE_CURSOR, Cursor.TEXT_CURSOR, Cursor.WAIT_CURSOR, Cursor.E_RESIZE_CURSOR, Cursor.NE_RESIZE_CURSOR, Cursor.NW_RESIZE_CURSOR, Cursor.NW_RESIZE_CURSOR, Cursor.N_RESIZE_CURSOR, Cursor.SE_RESIZE_CURSOR, Cursor.SW_RESIZE_CURSOR, Cursor.SW_RESIZE_CURSOR, Cursor.S_RESIZE_CURSOR, Cursor.W_RESIZE_CURSOR}; public static void main( String[] args ) { ChangingMousePointer changingMousePointerExample = new ChangingMousePointer(); changingMousePointerExample.go(); } public void go() { f = new Frame( "Various Mouse Pointers Example" ); f.setLayout( new GridLayout( (int) ( cursorPointerArray.length / 3 ) + 1, 3, 20, 20 ) ); for( int i = 0; i < cursorPointerArray.length; i++ ) { b = new Button( new String( cursorPointerStringArray[i] ) ); b.addActionListener( this ); f.add( b ); } f.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent we ) { System.exit( 0 ); } } ); f.pack(); f.setVisible( true ); } public void actionPerformed( ActionEvent ae ) { String st = ( (Button) ae.getSource() ).getActionCommand(); for( int i = 0; i < cursorPointerStringArray.length; i++ ) { if( cursorPointerStringArray[i].equals( st ) ) { System.out.println( st ); f.setCursor( Cursor.getPredefinedCursor( cursorPointerArray[i] ) ); break; } } } }