Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

How to recognize the ActionEvent in a FocusLost method??

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have a class which implements FocusListener,ActionListener. This Focus listener is used for a field named "Field 1" and the ActionListener is used for the buttons in the class. I have 2 buttons 'Save', 'Cancel'.

The validation for Field 1 should happen only for Save. The validation i am doing is the Field 1 should have 10 digits. If its not, it will throw error to the user.

The problem is when I click on 'Cancel' button, it is going into FocusLost() method and finding that "Field 1" is not having 10 digits and throwing error. Its not going into the actionPerformed() method of Cancel button. So, i was not able to execute Cancel button.

How will i identify that I clicked Cancel button (ActionEvent) in FocusLost() method??

Thanks in Advance
 
Sheriff
Posts: 22647
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
FocusEvent has a method called getOppositeComponent(). This returns the component that has gained the focus on focusLost events, and the component that has lost the focus on focusGained events.
 
Priya Sri
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rob !!
Its working fine !!
 
It's a tiny ad. At least, that's what she said.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic