This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Multiple ActionListeners for the enter key  RSS feed

 
S Garcia
Greenhorn
Posts: 8
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new to Java & I'm wondering if it is possible to have the enter key trigger
different listeners.

This is the set up:
The user enters data which gets validated & then populates an array.
Once the array is full a report is run.
I would like the enter to trigger both actions.

The code in the 2 listeners works perfectly & I'm getting into case 3:
just fine.
jButtonEnter.addActionListener(lisReport); doesn't do anything
but jButtonRun.addActionListener(lisReport); works perfectly.

So undoubtedly I've missed something simple.




Thanks for the help!
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
not really sure what you're getting at here, so I'll just guess based on the title

say you have this

you take the code from the actionListeners and put that code into separate methods
then call those methods from the single actionListener
so the above changes to
 
S Garcia
Greenhorn
Posts: 8
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.

I just figured in out. I was listening to the wrong object.

I had tried to listen to jScrollPane1 & jTextArea1 which didn't work.
When I listened to jTextField3 it worked perfectly.

Thanks again!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!