Results 1 to 2 of 2
  1. #1
    loore is offline Member
    Join Date
    Mar 2012
    Posts
    1
    Rep Power
    0

    Default java help: mouse insensitive to the hole

    hi guys..im having a problem with this code. The following codes produces a circle with a hole in the middle. i have to code it in such a way that the mouse should be insensitive with the hole. i.e. when i drag the circle holding on the hole, it should b dragged. i have done this with a square it works perfectly but not this circle. guys help please my due date is tmrw morning. thank you so much in advance.



    Java Code:
    import java.awt.*;
    import java.awt.geom.*;
    
    public class CircleWithHole extends Circle {
       int holeSize ;
       
       public CircleWithHole(int left, int top, int size, int holeSize) {
          super(left,top,size) ;
          this.holeSize = holeSize ;
       }
       
       public void draw(Graphics2D g) {
          Area circle = new Area(new Ellipse2D.Double(left,top,size,size)) ;
          int gap = (size-holeSize)/2 ;
          Area hole = new Area(new Ellipse2D.Double(left+gap, top+gap, holeSize,holeSize)) ;
          circle.subtract(hole) ;
          g.setPaint(paint);
          g.fill(circle) ;
          g.setPaint(Color.black) ;
          g.draw(circle) ;
       }
       
       public boolean touch(int x, int y) {
          double a = x - (left + 0.5 + size) ; 
          double b = y - (top + 0.5 + size) ;
          double c = Math.hypot(a,b) ;
    //      To ensure figure does not jump to cursor position from initial position
          dx = x - left ;
          dy = y - top ;
          return c<= 0.5 + size ;
       }
    }
    Last edited by Norm; 03-11-2012 at 09:10 PM. Reason: added code tags

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default Re: java help: mouse insensitive to the hole

    with a square it works perfectly but not this circle.
    What is the difference between the code that works and this code?

Similar Threads

  1. Making string insensitive to upper or lower case
    By ahmedaa16 in forum New To Java
    Replies: 0
    Last Post: 10-21-2011, 01:59 PM
  2. Security hole by Race condition
    By simorgh in forum Threads and Synchronization
    Replies: 0
    Last Post: 03-24-2010, 05:10 AM
  3. Mouse Listener for mouse floating over object?
    By Krooger in forum AWT / Swing
    Replies: 1
    Last Post: 11-18-2009, 05:34 AM
  4. [SOLVED] Making Switch Case Insensitive?
    By iPetey in forum New To Java
    Replies: 6
    Last Post: 04-09-2009, 05:46 PM
  5. Replies: 3
    Last Post: 09-11-2008, 04:00 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
  •