Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #34877
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Event overhead, does it matter? |
| Date | 2016-07-13 10:45 -0400 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <nm5k5j$1r8v$1@gioia.aioe.org> (permalink) |
| References | <9c586a05-dbbd-4ebc-b61c-a53269421858@googlegroups.com> |
On 7/13/2016 9:51 AM, Eric Douglas wrote:
> Is one method more efficient (speed, memory) or is it just a matter of personal preference?
> Method 1:
> public class MyTree extends JTree implements FocusListener {
> scrollPane.addFocusListener(this);
> addFocusListener(this);
> public void focusGained(final FocusEvent e) {
> if (e.getComponent() == this) {
> // tree gained focus
> }
> if (e.getComponent() == scrollPane) {
> // scroll pane gained focus
> }
> }
> Method 2:
> public class MyTree extends JTree {
> scrollPane.addFocusListener(new FocusListener() {
> public void focusGained(final FocusEvent e) {
> // scroll pane gained focus
> }
> });
> addFocusListener(new FocusListener() {
> public void focusGained(final FocusEvent e) {
> // tree gained focus
> }
> });
You should totally ignore speed and memory considerations.
The difference will be white noise.
Criteria should be readability and a natural design.
I would be inclined to go for method 2, because
it is really two focus listeners, using the same and
having an if within the methods is a design kludge.
Arne
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
Event overhead, does it matter? Eric Douglas <e.d.programmer@gmail.com> - 2016-07-13 06:51 -0700 Re: Event overhead, does it matter? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-13 10:36 -0400 Re: Event overhead, does it matter? Arne Vajhøj <arne@vajhoej.dk> - 2016-07-13 10:45 -0400
csiph-web