Solved

Catch mouseEntered or mouseExited while Dragging

Posted on 1998-12-07
5
620 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now