Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to fire event automatically

 
Govinda Reddy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
using swing i developed one login screen which contains ok button, cancel button and two text boxes for username and password.i am hardcoded username and password.i want to login with out mouseclick on the OK button.
In ActionPerformed method i am checking username and password. in my case loginSuccess() method returns always true.

public void actionPerformed(ActionEvent e)
{
String command=e.getActionCommand();

if(command.equalsIgnoreCase("OK")){
if(loginSuccess(){
executeApplication();
}
}

if(command.equalsIgnoreCase("Cancel"))
{
closeDialog();
}

}

how to execute actionPerformed() method without clicking on ok button.

please help me how to solve this problem.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This forum is meant for SCJP. It would be better if you posted this in our Swing forum.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Barry Gaunt:
This forum is meant for SCJP. It would be better if you posted this in our Swing forum.

Moving to the Swing forum.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> how to execute actionPerformed() method without clicking on ok button.

set the OK button as the default
getRootPane().setDefaultButton(okButton);
 
Cp Baherwani
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
doClick (inherited from AbstractButton)
public void doClick()
Programmatically perform a "click". This does the same thing as if the user had pressed and released the button.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic