Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: mouse Released no work!!

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default mouse Released no work!!

    hi all
    i'm trying to a function that listen to the mouse
    basically i want to start drawing square till the user released the mouse
    and than the square will disappear
    this is my function please help
      public void StartDelete()
        {
                        _pointX = new int[4];
                        _pointY = new int[4];
     
                      addMouseListener(new MouseAdapter(){
                @Override
                public void mousePressed(MouseEvent e){
                    if(_clearFlag)
                    {
                  _pointX[3] = e.getX();
                   _pointY[3]= e.getY();
                    }
                }
            });
            addMouseMotionListener(new MouseAdapter(){
     
                public void mouseDragged(MouseEvent e){
                    if(_clearFlag)
                    {
                           _pointX[0]=(e.getX()-_pointX[3])+_pointX[3];
                           _pointY[0]=_pointY[3];
                           _pointX[1]= e.getX();
                           _pointY[1] = e.getY();
                           _pointX[2]=_pointX[3];
                           _pointY[2]=e.getY();
     
                           repaint();
     
                }
                }
            });
                  addMouseMotionListener(new MouseAdapter(){
     
                public void mouseReleased(MouseEvent e){
                    if(_clearFlag)
                    {
                           _pointX=null;
                           _pointY=null;
     
                           repaint();
     
                }
                }
            });
        }
    and my repaint
    public void paintComponent(Graphics g){
     
            super.paintComponent(g);
            //////////////////////////////--------------------Display obstacle points----------------//////////////////////////////////////////////////
            g.setColor(Color.BLACK);
            LinkedList[] positive =  new LinkedList[_obstacleDataPoints.getPositiveArraySize()] ;
            LinkedList[] negative = new LinkedList[_obstacleDataPoints.getNegativeArraySize()];
            negative = _obstacleDataPoints.getNegativeNumbers();
            positive = _obstacleDataPoints.getPositiveNumbers();
     
            for(int i=0;i<positive.length-1;i++)
            {
                  PointX x;
               for(int j=0;j<positive[i].size();j++)
               {
                    x= (PointX)positive[i].get(j);
                 //  IfPointOutOfFrame(x.getX(),i);
     
                    g.fillOval(ConvertXRobotDataToDraw(x.getX()),ConvertYRobotDataToDraw(i), 4, 4);
     
     
               }
     
            }
                    for(int i=1;i<negative.length-1;i++)
            {
                  PointX x;
               for(int j=0;j<negative[i].size();j++)
               {
                    x= (PointX)negative[i].get(j);
                 //  IfPointOutOfFrame(x.getX(),i);
     
                    g.fillOval(ConvertXRobotDataToDraw(x.getX()),ConvertYRobotDataToDraw(-i), 4, 4);
     
     
               }
     
            }
    [B]if(_pointX!=null&&_pointY!=null)
        g.drawPolygon(_pointX, _pointY, 4);[/B]
     
     }

    in run time this mouseReleased dosent work he wont get in to this func when i Release the button
    10X


  2. #2
    Member
    Join Date
    Jan 2010
    Location
    Oxford, UK
    Posts
    30
    Thanks
    2
    Thanked 7 Times in 7 Posts

    Default Re: mouse Released no work!!

    MouseMotionListener doesn't specify mouseReleased, so I don't think that method is ever being called. Have your anonymous class implement MouseListener instead.

    Also, why are you using different anonymous classes for the various methods? You only need a single implementation of MouseListener and a single implementation of MouseMotionListener.

Similar Threads

  1. Replies: 8
    Last Post: April 21st, 2013, 08:20 AM
  2. How to get Mouse Position even if it is not within our application?
    By Freaky Chris in forum Java Programming Tutorials
    Replies: 2
    Last Post: January 4th, 2012, 09:57 AM
  3. How can i point the mouse over a html element within the web browser?
    By bobomonkey in forum Java Theory & Questions
    Replies: 2
    Last Post: October 18th, 2009, 12:37 PM
  4. my run program does not work
    By rman27bn in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 16th, 2009, 09:13 AM
  5. How to create a system wide mouse or keyboard hook?
    By Freaky Chris in forum Java Native Interface
    Replies: 17
    Last Post: June 17th, 2009, 01:06 PM