Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #34877
| Path | csiph.com!aioe.org!.POSTED!not-for-mail |
|---|---|
| From | Arne Vajhøj <arne@vajhoej.dk> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Event overhead, does it matter? |
| Date | Wed, 13 Jul 2016 10:45:07 -0400 |
| Organization | Aioe.org NNTP Server |
| Lines | 49 |
| Message-ID | <nm5k5j$1r8v$1@gioia.aioe.org> (permalink) |
| References | <9c586a05-dbbd-4ebc-b61c-a53269421858@googlegroups.com> |
| NNTP-Posting-Host | 7SK6yTFfqwlIPNBLl3l7Qg.user.gioia.aioe.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Complaints-To | abuse@aioe.org |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 |
| X-Notice | Filtered by postfilter v. 0.8.2 |
| Xref | csiph.com comp.lang.java.programmer:34877 |
Show key headers only | View raw
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