-
create a custom mouse cursor
hello everyone,
i had a problem in making a triangle shape cursor in java applet. i had already made a moving zig-zag object as a cursor by using MouseListener, MouseMotionListener. can anybody please help me? thank you in advance.
p/s: below is the syntax.
package org.me.hello;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Math;
public class NoBackbuffer1 extends Applet
implements MouseListener, MouseMotionListener {
int width, height;
int mx, my; // the mouse coordinates
Point[] points;
int N = 100;
public void init() {
width = getSize().width;
height = getSize().height;
setBackground( Color.BLACK );
mx = width/2;
my = height/2;
points = new Point[ N ];
for ( int i = 0; i < N; ++i ) {
int x = (int)(( Math.random() ) * width / 3);
int y = (int)(( Math.random() ) * height / 3);
points[i] = new Point( x, y );
}
addMouseMotionListener( this );
}
public void mouseMoved( MouseEvent e ) {
mx = e.getX();
my = e.getY();
showStatus( "Mouse at (" + mx + "," + my + ")" );
repaint();
e.consume();
}
public void mouseDragged( MouseEvent e ) {
mx = e.getX();
my = e.getY();
showStatus( "Mouse at (" + mx + "," + my + ")" );
repaint();
e.consume();
}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseClicked(MouseEvent e){}
public void paint( Graphics g ) {
g.setColor( Color.cyan );
for ( int j = 1; j < N; ++j ) {
Point A = points[j-1];
Point B = points[j];
g.drawLine( mx+A.x, my+A.y, mx+B.x, my+B.y );
}
}
}
-
you could use the setCursor() method... but.
you could replace your paint() method with this:
Code:
public void paint( Graphics g ) {
g.setColor( Color.cyan );
//since mx and my are mouse coordinates, you can just draw a triangle according to mx and my
g.drawLine(mx, my, mx, my+5);
g.drawLine(mx, my, mx + 5, my);
g.drawLine(mx, my+5, mx+5, my);
}
}
this might not be perfect, since i havent tested it, but thats basically the idea
i dont understand why you need to draw 100 lines in your paint method though (probably since i dont know how it looks like)
-
thank you for the idea Skyuzo.
I am a new learner of Java programming. i am using a java programming for my final year projects.
could you please tell me what do you mean of "why you need to draw 100 lines in your paint method"?
i would like to make paint program with a triangle custom cursor.
thank you.
Similar Threads
-
Replies: 4
Last Post: 04-14-2006, 09:09 AM
-
Replies: 0
Last Post: 04-04-2003, 05:25 PM
-
By Michael Sorens in forum XML
Replies: 0
Last Post: 12-11-2002, 06:05 PM
-
Replies: 1
Last Post: 11-27-2001, 06:53 AM
-
By SKoRPioN9x in forum Web
Replies: 3
Last Post: 08-02-2001, 07:54 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks