Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 649
  • Last Modified:

Catch mouseEntered or mouseExited while Dragging

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
baresse
Asked:
baresse
  • 3
  • 2
1 Solution
 
diakovCommented:
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
 
baresseAuthor Commented:
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
 
diakovCommented:
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
 
diakovCommented:
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
 
baresseAuthor Commented:
It was nearly my solution...

Thanks for having look at my problem !

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now