This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
not sure I'm reading this right, but if you want a keyEvent to fire off what an actionEvent does,
the simple way is to put the actionEvent stuff into a separate method, which is then available to
be called from elsewhere
now, any other event/whatever can call doSomething()
Joined: Jan 28, 2012
Campbell, the key-bindings are definitely relevant to my needs and I had no idea there was such a thing.
That certainly solves a big part of my problem, thanks for that.
Michael, you're on the right track.
In actual fact, it is currently the solution I am using for my custom component, but I would really like to simplify how it is used.
The problem is that this approach is implementation specific. Every time I use the component, I need to remember to intercept all related low level events and call doSomething() from them.
This would be fine if I didn't plan to reuse this component regularly, and I will be using this component regularly.
So what I actually want to be able to do is group all related low level events and define that group as an "ActionEvent" or even "MyCustomEvent".
Hypothetically, I would prefer to say some thing like: "A mouse release, tab key, mouseWheelMove should be treated as one kind of event, called "MyCustomEvent". The only thing you need to do when using this component is to intercept "MyCustomEvent".
Is this possible? (sorry if I wasn't clear enough before)
Joined: Jun 09, 2003
this is not what you're after, but it might give you something to play around with.
(just an example of grouping the events - in the 'masks')
run the code (as is), click the textArea and the mouse messages will print out.
type a key, and the key messages will print out.
uncomment the block (leave the commented-out line as is), now repeat the above
the events that display the messages have been consumed, but the key typed will still appear in the textArea
now uncomment that extra line, re-run and no key typed will appear
Joined: Oct 13, 2005
Steve Simon wrote:Thanks guys, . . . I had no idea there was such a thing. . . . thanks for that.
. . . this approach is implementation specific. Every time I use the component, I need to remember to intercept all related low level events . . .
Not sure what to recommend, but that sort of thing worries me. It may be possible for some components to be fired by several different things, however. I think you can fire a button with a click, space or enter key, but you would have to verify that. In the Java Tutorials, you tend to find things I don’t like, eg addActionListener(this) or the whole program inside the main method, but when you allow for that, it is one of the best sources of information available. That section should give you all sorts of information about listeners, (I think, including advice to use the highest‑level listener you can).
Joined: Jan 28, 2012
Ok cool thank you very much to both of you, I really appreciate the attention.
The Java tutorials are indeed great, so I guess I should rather look at them more often than stick with my current preference: looking at the source code (which, by the way, involves such 'tight-coupling' of classes and interfaces its just bewildering to trawl through!)
subject: Translating from low-level event to semantic event