Mouse Events

i have a program which have deprecated
Mouse Events

Please take a look:

  public boolean mouseMove(Event event, int i, int j)
    {
        if(j <= iRowHeight)
        {
            int k = i;
            i = (i + iX) - iGridWidth;
            int l;
            for(l = iColCount - 1; l >= 0; l--)
            {
                if(i > -7 && i < 7)
                    break;
                i += iColWidth[l];
            }

            if(l >= 0)
            {
                if(!bDrag)
                {
                    setCursor(11);
                    bDrag = true;
                    iXDrag = k - iColWidth[l];
                    iColDrag = l;
                }
                return true;
            }
        }
        return mouseExit(event, i, j);
    }


how can i change to the new method?
processMouseEvent(MouseEvent e)??
Please help
Clement

LVL 1
opabcAsked:
Who is Participating?
 
OviConnect With a Mentor Commented:
Let's say you have a Canvas on wich you want to implement this method. You will do something like this :

Canvas c = new Canvas;
c.addMouseMotionListener(new MouseMotionAdapter() {
      public void mouseMoved(MouseEvent e) {
      // your code here
int i = e.getX();
int j = e.getY()
       if(j <= iRowHeight)
                            {
                                int k = i;
                                i = (i + iX) - iGridWidth;
                                int l;
                                for(l = iColCount - 1; l >= 0; l--)
                                {
                                    if(i > -7 && i < 7)
                                        break;
                                    i += iColWidth[l];
                                }

                                if(l >= 0)
                                {
                                    if(!bDrag)
                                    {
                                        setCursor(11);
                                        bDrag = true;
                                        iXDrag = k - iColWidth[l];
                                        iColDrag = l;
                                    }
                                    return true;
                                }
                            }
      }
});


Using MouseMotionAdapter let you implement only mouseMoved method if you want to. If you use MouseMotionListener instead, you will be forced to implement both mouseMoved and mouseDragged metods.

Good luck.
0
 
opabcAuthor Commented:
I still dun understand
can u convert the entire code that i post to the new method processMouseEvent(MouseEvent e)??
0
 
OviCommented:
protected void processMouseEvent(MouseEvent e) Processes mouse events occurring on this component by dispatching them to any registered MouseListener objects. This method is not called unless mouse events are enabled for this component. Mouse events are enabled when one of the following occurs: A MouseListener object is registered via addMouseListener. Mouse events are enabled via enableEvents. Parameters:e - the mouse event.Since: JDK1.1 (AWT help)


What Java are you using in your application? In awt, this method is protected wich meens your component inherit this method from his parent
and automatically execute'it on a mouse event to your component. Depending on the type of this event (mouseMove, mouseDragg, etc) he send this event to appropiate mouse listener to process'it. So my example is applicable in this case. For more details, please be more concrete about your code.
0
All Courses

From novice to tech pro — start learning today.