• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

delegating event handling

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

I am trying to develop a small login application.

I have a simple login gui called LoginFrame.java which contains a textfield and a password field and a submit button. When the user enters values in textfield and password and presses the Submit button, the textfield and password should be validated.

I want to design this in a way such that all the events generated by LoginFrame.java should be handled in another class called LoginFrameEventHandler.java which implements all the corresponding event listeners.
Ex: JButton submit = new JButton();
submit.addActionListener(new LoginFrameEventHandler());

Now when the submit button is pressed, the event is fired properly, but I am not able to get the reference to the textfield and the password field of LoginFrame.java in the LoginFrameEventHandler.java.

Any suggestions?


Thanks in advance

Meghana
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Meghana Reddy:
I want to design this in a way such that all the events generated by LoginFrame.java should be handled in another class called LoginFrameEventHandler.java which implements all the corresponding event listeners.
Ex: JButton submit = new JButton();
submit.addActionListener(new LoginFrameEventHandler());

Now when the submit button is pressed, the event is fired properly, but I am not able to get the reference to the textfield and the password field of LoginFrame.java in the LoginFrameEventHandler.java.



Well you could have your listener accept those two fields in its constructor, so something like:
JButton submit = new JButton();
submit.addActionListener(new LoginFrameEventHandler(userField, passField));
 
Meghana Reddy
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Brian

I am in fact sending the reference of LoginFrame to the constructor of LoginFrameEventHandler since the requirement calls for disposing the LoginFrame once login is successful and then show another GUI.

Thanks for the help.

Meghana
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic