Solved

Catch mouseEntered or mouseExited while Dragging

Posted on 1998-12-07
5
635 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 161
Desingning Refactoring existing code 2 46
Facing this issue for maven proxy setting 2 45
swing controls 2 38
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

752 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