[4992] in java-interest
Re: How can I distinguish which button was pressed?
daemon@ATHENA.MIT.EDU (Greg Ewing)
Thu Jan 25 12:04:34 1996
Date: Tue, 23 Jan 96 19:45:13 EST
From: grege@optimation.com.au (Greg Ewing)
To: java-interest@java.sun.com
> From NewsGroup_comp-lang-java Sat Jan 20 22:14 EST 1996
> From: NewsGroup_comp-lang-java
> >From: swerling@bway.net (Steven Swerling)
> Subject: Re: How can I distinguish which button was pressed?
> Date: Fri, 19 Jan 1996 19:01:05 GMT
> Nntp-Posting-Host: dial66.bway.net
> X-Newsreader: Forte Free Agent 1.0.82
>
> switch@utopia.medison.co.kr (SeungWook Choi) wrote:
>
> >In handling mouse events, how can I distinguish which mouse button
> >was pressed ?
> >mouseDown() seems to check whether mouse button is pressed or not.
> >Is there anybody who will let me know?
>
> The way I do it is to keep instance variables storing each widget
> whose events I must handle. Then, in the handleEvent() method, you
> just see if the (event.target == myWidget). I'm not sure how "elegant"
> this would be considered, and I am also interested in the "right" way
> to do this, if anyone has some suggestions. All I know is, it can't be
> right to do it the way Sun does it in the sample code by checking to
> see if the target is instanceOf some class, since, as you already
> know, you cannot distinguish to widgets that way.
>
> ... stuff deleted
>
I think you have misunderstood the question.
This is how I distinguish mouse button clicks:
public boolean handleEvent(Event evt) {
switch(evt.id) {
case Event.MOUSE_DOWN:
if (evt.modifiers == evt.CTRL_MASK) {
System.out.println("Right button pressed");
} else {
if (evt.modifiers == evt.ALT_MASK) {
System.out.println("Middle btn pressed");
} else {
System.out.println("Left button pressed");
}
}
return true;
}
}
return super.handleEvent(evt);
}
This works for Solaris (actually I haven't tested the middle button yet),
however I seem to recall reading somewhere that Win95 may be slightly
different (META_MASK instead of CTRL_MASK ??).
GREG
greg@optimation.com.au
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com