Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Catch mouseEntered or mouseExited while Dragging

Posted on 1998-12-07
5
Medium Priority
?
643 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 800 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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…
Suggested Courses

730 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