Solved

mouse event handling...

Posted on 1997-11-17
8
216 Views
Last Modified: 2010-04-16
I have a question about mouse event handling.  Why can the mouseDrag(), mouseMove(), mouseEnter(), and mouseExit() methods be used by simply entering commands, while the mouseUp() and mouseDown()methods have to be "checked," (i.e. "if(evt.modifiers == 0))."  I'm just wondering if there's something I don't understand about event handling.  
0
Comment
Question by:Raydot
  • 4
  • 3
8 Comments
 
LVL 3

Author Comment

by:Raydot
ID: 1230749
Oh, and why does the evt.modifiers evaluate to 0 when the mouse is clicked instead of to 1, which seems more logical?

Thanks,

Raydot.
0
 
LVL 4

Accepted Solution

by:
rembo earned 50 total points
ID: 1230750

There is no difference between the different methods
and how they go about handling events.

Most likely what you've seen is some inconsistent
programming style.  

The 0 vs. 1 thing is an old UNIX holdover.  

-Tony


0
 
LVL 4

Expert Comment

by:russgold
ID: 1230751
OK, you're both right.  What I was looking at was a program that checks whether the left or right mouse buttons are clicked.  So as to Tony's comment, the programming snippet I gave, out of context, was "inconsistent" with the other mouse event methods in the program I was describing in that it utilized an if...else construct, like russgold suggests, to check which button had been clicked.  

Just to get my $$$'s worth, these methods (mouseDown, mouseUp, mouseDrag, etc.) are checked by Java automatically?  They handle all mouse events and I don't have to do anything else? (e. g. initialize, monitor, thread, etc.)

Dave.

0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 3

Author Comment

by:Raydot
ID: 1230752

Russ is correct, I was only speaking to the fact that there
is no actual difference between the methods in terms of
what they are required to handle.  What you can do
with them are different.  

Events in 1.02 and 1.1 are completely different.  However,
since you're asking about 1.02 methods, we'll stick to
those.  

The events will get passed to the default event handler
for the container if you don't handle them.  There is
no need to initalize, monitor or anything if you don't
need to monitor those events.  


0
 
LVL 4

Expert Comment

by:rembo
ID: 1230753
WHOA! (Record stops, bar clears out...) I'm talking about 1.02 events?  I'm reading a book on Visual J++ 1.1, so I thought I was dealing with Java 1.1.  How do you know these are 1.02 events, and if they are then how is it done in 1.1?
0
 
LVL 3

Author Comment

by:Raydot
ID: 1230754

While mouseMove, mouseEnter, etc. all still work in 1.1,
they are 1.02 event handling methods and are deprecated.
Methods are handled using mouseListener() and mouseMotionListener() and adapter classes.  It's a
completely different model.

The code you are writing will still work now, but
probably not in the the next real release of Java (2.0 -
1.2 will still be fine).

So, the deal is that you can do things the way you are
or you can move to the new event model.  

Even with 1.1 though, there's no need to handle those
events if you don't need to do anything with them.


0
 
LVL 4

Expert Comment

by:rembo
ID: 1230755
Mmmmm...this book I'm going through sucks.  That's like the third outdated method I've come across in it.  Maybe I'll e-mail the author...

Anyway, thanks Tony.

Raydot.
0
 
LVL 3

Author Comment

by:Raydot
ID: 1230756

I review a lot of books, and I'd be happy to recommend
a good text for you.


-Tony


0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
netstat -ano | find "8000" and taskkill /f /pid 2984 3 84
table example 4 32
What's wrong with this code? 4 28
running on tomcat not jboss eap 7.0 3 19
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…
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This video teaches viewers about errors in exception handling.

808 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