Solved

Catch mouseEntered or mouseExited while Dragging

Posted on 1998-12-07
5
632 Views
Last Modified: 2008-03-10
Hi,

I've written an applet in which I want to catch the mouseEntered and mouseExited event on a component while the user is dragging over it.

It's works fine with Netscape, but not with Internet Explorer...

In Internet Explorer the MouseExited() method raises when the user release the button !

It's a problem for me because, I use this method to automatically scroll my image in a scrollpane when the user exits the component while he's dragging.

I'm looking for code...

Thanks
0
Comment
Question by:baresse
  • 3
  • 2
5 Comments
 
LVL 8

Expert Comment

by:diakov
ID: 1228854
Hi 'baresse',

This example I made to test the feature (or bug :-) you described.
-----------------
/*
      A basic extension of the java.applet.Applet class
 */

import java.awt.*;
import java.applet.*;

public class applet_tester extends Applet
{
      public void init()
      {
            // Take out this line if you don't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller
            symantec.itools.lang.Context.setApplet(this);
      
            // This code is automatically generated by Visual Cafe when you add
            // components to the visual environment. It instantiates and initializes
            // the components. To modify the code, only use code syntax that matches
            // what Visual Cafe can generate, or Visual Cafe may be unable to back
            // parse your Java file into its visual environment.
            //{{INIT_CONTROLS
            setLayout(null);
            setSize(426,266);
            tester_button = new java.awt.Button();
            tester_button.setLabel("Tester");
            tester_button.setBounds(144,96,151,32);
            tester_button.setBackground(new Color(12632256));
            add(tester_button);
            status = new java.awt.Label("outside",Label.CENTER);
            status.setBounds(60,156,311,37);
            add(status);
            //}}
      
            //{{REGISTER_LISTENERS
            SymMouse aSymMouse = new SymMouse();
            tester_button.addMouseListener(aSymMouse);
            //}}
      }
      
      //{{DECLARE_CONTROLS
      java.awt.Button tester_button;
      java.awt.Label status;
      //}}

      class SymMouse extends java.awt.event.MouseAdapter
      {
            public void mouseExited(java.awt.event.MouseEvent event)
            {
                  Object object = event.getSource();
                  if (object == tester_button)
                        testerButton_MouseExited(event);
            }

            public void mouseEntered(java.awt.event.MouseEvent event)
            {
                  Object object = event.getSource();
                  if (object == tester_button)
                        testerButton_MouseEntered(event);
            }
      }

      void testerButton_MouseEntered(java.awt.event.MouseEvent event)
      {
            // to do: code goes here.
                  
            //{{CONNECTION
            // Set the text for Label...
            status.setText("Inside");
            //}}
      }

      void testerButton_MouseExited(java.awt.event.MouseEvent event)
      {
            // to do: code goes here.
                  
            //{{CONNECTION
            // Set the text for Label...
            status.setText("Outside");
            //}}
      }
}

----------------
It worked fine on the Netscape 4.5
It worked fine on IE 4.0

Can you please test it on your machine and tell me?

Cheers,
  Nikolay

0
 
LVL 1

Author Comment

by:baresse
ID: 1228855
Yes this feature is fine for me too...

But, it's while the user is "Dragging" with the mouse there is a problem...

My component has a MouseMotionListener too, and implements some
feature is the "mouseDragged()" method.

The problem is that the "mouseEntered()" and the "mouseExited()" methods aren't executed while the user is "dragging" (i.e. mouseDragged() method is executing). They are just fire after the user releases the mouse button and so stop dragging.

Sorry.
0
 
LVL 8

Expert Comment

by:diakov
ID: 1228856
I see your point. I modified the example and it really does not work under IE 4.0.

I can suggest a nasty work around. When you detect IE in you applet, start a separate thread that checks for the mouse position over the component and does what it needs.

Cheers,
  Nik
0
 
LVL 8

Accepted Solution

by:
diakov earned 200 total points
ID: 1228857
Ok, another attempt.

This I tested under my IE.
While dragging when a drag event comes to you, it has valid x, y. In the handler you can check where the mouse whent and over which component it is. You don't actually need thread. Just insert
if (comonentX.contains(event.getX(), event.getY()))
{
  //write the code
}
The draging events come as the mouse move so you only need to process the coordinates accordingly.

I'll post again the code example that helped me do that.
-------------------------------------
/*
      A basic extension of the java.applet.Applet class
 */

import java.awt.*;
import java.applet.*;

public class applet_tester extends Applet
{
      public void init()
      {
            // Take out this line if you don't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller
            symantec.itools.lang.Context.setApplet(this);
      
            // This code is automatically generated by Visual Cafe when you add
            // components to the visual environment. It instantiates and initializes
            // the components. To modify the code, only use code syntax that matches
            // what Visual Cafe can generate, or Visual Cafe may be unable to back
            // parse your Java file into its visual environment.
            //{{INIT_CONTROLS
            setLayout(null);
            setSize(426,266);
            tester_button = new java.awt.Button();
            tester_button.setLabel("Tester");
            tester_button.setBounds(144,96,151,32);
            tester_button.setBackground(new Color(12632256));
            add(tester_button);
            status1 = new java.awt.Label("outside",Label.CENTER);
            status1.setBounds(60,156,311,37);
            add(status1);
            status2 = new java.awt.Label("outside",Label.CENTER);
            status2.setBounds(60,48,311,37);
            add(status2);
            status3 = new java.awt.Label("outside",Label.CENTER);
            status3.setBounds(48,216,311,37);
            add(status3);
            //}}
      
            //{{REGISTER_LISTENERS
            SymMouse aSymMouse = new SymMouse();
            tester_button.addMouseListener(aSymMouse);
            SymMouseMotion aSymMouseMotion = new SymMouseMotion();
            this.addMouseMotionListener(aSymMouseMotion);
            tester_button.addMouseMotionListener(aSymMouseMotion);
            //}}
      }
      
      //{{DECLARE_CONTROLS
      java.awt.Button tester_button;
      java.awt.Label status1;
      java.awt.Label status2;
      java.awt.Label status3;
      //}}

      class SymMouse extends java.awt.event.MouseAdapter
      {
            public void mouseExited(java.awt.event.MouseEvent event)
            {
                  Object object = event.getSource();
                  if (object == tester_button)
                        testerButton_MouseExited(event);
            }

            public void mouseEntered(java.awt.event.MouseEvent event)
            {
                  Object object = event.getSource();
                  if (object == tester_button)
                        testerButton_MouseEntered(event);
            }
      }

      void testerButton_MouseEntered(java.awt.event.MouseEvent event)
      {
            // to do: code goes here.
                  
            //{{CONNECTION
            // Set the text for Label...
            status2.setText("Inside");
            //}}
      }

      void testerButton_MouseExited(java.awt.event.MouseEvent event)
      {
            // to do: code goes here.
                  
            //{{CONNECTION
            // Set the text for Label...
            status2.setText("Outside");
            //}}
      }

      class SymMouseMotion extends java.awt.event.MouseMotionAdapter
      {
            public void mouseMoved(java.awt.event.MouseEvent event)
            {
                  Object object = event.getSource();
                  if (object == applet_tester.this)
                        appletTester_MouseMoved(event);
                  else if (object == tester_button)
                        testerButton_MouseMoved(event);
            }

            public void mouseDragged(java.awt.event.MouseEvent event)
            {
                  Object object = event.getSource();
                  if (object == applet_tester.this)
                        appletTester_MouseDragged(event);
                  else if (object == tester_button)
                        testerButton_MouseDragged(event);
            }
      }

      void appletTester_MouseDragged(java.awt.event.MouseEvent event)
      {
            // to do: code goes here.
                  
            //{{CONNECTION
            // Set the text for Label...
            status1.setText("Dragged in applet");
            status3.setText(Integer.toString(event.getX(), 10) + ":" + Integer.toString(event.getY(), 10));
            //}}
      }

      void testerButton_MouseDragged(java.awt.event.MouseEvent event)
      {
            // to do: code goes here.
                  
            //{{CONNECTION
            // Set the text for Label...
            status1.setText("Dragged in button");
            status3.setText(Integer.toString(event.getX(), 10) + ":" + Integer.toString(event.getY(), 10));
            //}}
      }

      void appletTester_MouseMoved(java.awt.event.MouseEvent event)
      {
            // to do: code goes here.
                  
            //{{CONNECTION
            // Set the text for Label...
            status3.setText(Integer.toString(event.getX(), 10) + ":" + Integer.toString(event.getY(), 10));
            //}}
      }

      void testerButton_MouseMoved(java.awt.event.MouseEvent event)
      {
            // to do: code goes here.
                  
            //{{CONNECTION
            // Show the Label
            status3.setText(Integer.toString(event.getX(), 10) + ":" + Integer.toString(event.getY(), 10));
            //}}
      }
}


-----------------
Cheers,
  Nikolay
0
 
LVL 1

Author Comment

by:baresse
ID: 1228858
It was nearly my solution...

Thanks for having look at my problem !

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
reverse digits of a number using for loop 5 52
hibernate jars 4 45
difference between sorce folder and folder in eclipise 3 29
Java basic valueOf question 1 29
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question