DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Mouse E

  1. #1
    Join Date
    Aug 2005

    Mouse E

    at the moment my applet displays a big black circle but i want the applet to draw a white circle where the mouse is. the mouse will point to the centre of the circle. i want to decide how big my circle will be where i want the top left corner of the mouse to be.

    import java.applet.Applet;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.geom.Ellipse2D;
    import java.awt.Rectangle;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseEvent;
    import java.awt.Color;

    public class MouseE extends Applet
    public MouseE()
    x1 = -1; // initialise (x1,y1) and (x2,y2) to -1
    y1 = -1; // the value '-1' is OUTSIDE the applet
    x2 = -1; // so, if, in the program, these variables are less than zero
    y2 = -1; // we KNOW that they don't currently represent a point on the image

    class MousePressListener implements MouseListener

    // do-nothing methods
    public void mousePressed(MouseEvent event){}
    public void mouseReleased(MouseEvent event){}
    public void mouseClicked(MouseEvent event){}
    public void mouseExited(MouseEvent event){}

    public void mouseEntered(MouseEvent event)
    x1 = event.getX();
    y1 = event.getY();



    MouseListener listener = new MousePressListener();

    public void paint(Graphics g)
    Graphics2D g2 = (Graphics2D) g;
    Ellipse2D.Double circle = new Ellipse2D.Double(0,0, 300, 300);

    public double x1;
    public double y1;
    public double x2;
    public double y2;


  2. #2
    Join Date
    Nov 2004
    The circle parameters represent the topLeft and the diameter(s), so if your
    mousePosition is going to be at the center then your circle should be drawn, in the
    appropriate mouseEvent(mousePressed, mouseMoved) like:

    g.drawOval(event.getX()-diameter/2, event.getY()-diameter/2, diameter, diameter);

    For an ellipse you must use diameterX & diameterY, this should work if you use the
    Graphics2D also.
    eschew obfuscation

Similar Threads

  1. Capturing Mouse Movements outside of screen resolution
    By Chris Eastwood in forum VB Classic
    Replies: 4
    Last Post: 03-28-2002, 01:26 PM
  2. Mouse Movement Playback
    By Eugene in forum VB Classic
    Replies: 4
    Last Post: 12-19-2000, 12:52 PM
  3. Mouse Movement Playback
    By Eugene in forum VB Classic
    Replies: 0
    Last Post: 12-19-2000, 11:13 AM
  4. Mouse Hook
    By Michael Culley in forum VB Classic
    Replies: 2
    Last Post: 12-10-2000, 01:56 PM
  5. Wheel Mouse In Access
    By Paul Harris in forum VB Classic
    Replies: 0
    Last Post: 03-13-2000, 04:07 PM

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
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

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

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.