 |
Author |
Topic: custom cursor (Read 888 times) |
|
James
|
custom cursor
« on: Jan 18th, 2005, 2:22pm » |
|
I searched this board a few days ago when I was looking into how to create a custom cursor and found a few posts asking the same question but no answers so I thought i'd post a working solution. Used as a method of a class that extends BApplet it seems to work for me. (BTW, I just started learning java last week so this may very well not be the optimal way of doing it, but it might save someone some time.) import java.awt.Cursor; import java.awt.Dimension; import java.awt.Toolkit; import java.awt.Image; import java.awt.Point; private final void customizeCursor() { Toolkit toolkit = getToolkit(); Dimension allowedDimensions = toolkit.getBestCursorSize(16, 16); System.out.println("allowed dimensions = "+allowedDimensions.width); int allowedColours = toolkit.getMaximumCursorColors(); if (!allowedDimensions.equals(new Dimension(0, 0)) && (allowedColours != 0)) { Image pencil; if(allowedDimensions.width>16) { pencil = reference to a 32x32 pixel image that you've previously loaded; }else { pencil = reference to a 16x16 pixel image that you've previously loaded; } if (pencil != null) { try { Cursor pencilcursor = toolkit.createCustomCursor(pencil,new Point(1, 15),"pencil_cursor"); this.setCursor(pencilcursor); }catch(Exception exc) { System.err.println("Unable to create custom cursor."); } } } } -- james
|
|
|
|
|