create a custom mouse cursor


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: create a custom mouse cursor

  1. #1
    Join Date
    Nov 2006
    Posts
    2

    Smile 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 );
    }
    }
    }

  2. #2
    Join Date
    Apr 2006
    Posts
    14
    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)

  3. #3
    Join Date
    Nov 2006
    Posts
    2

    Red face

    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

  1. Getting a GUI to run
    By Eric in forum Java
    Replies: 4
    Last Post: 04-14-2006, 10:09 AM
  2. Attn: Daniel Reber
    By joe in forum Database
    Replies: 0
    Last Post: 04-04-2003, 06:25 PM
  3. Replies: 0
    Last Post: 12-11-2002, 07:05 PM
  4. Getting a GUI to function
    By Eric in forum Java
    Replies: 1
    Last Post: 11-27-2001, 07:53 AM
  5. Changing Mouse Cursor
    By SKoRPioN9x in forum Web
    Replies: 3
    Last Post: 08-02-2001, 08: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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center