ActionEvent textfield checking
I have cashform with atttributes pin,sendername,receivername,senderphone,amount and another form accountfr开发者_JAVA技巧om with attributes pin,sendername receivername,senderphone,amount,bankname,account number..
both form have send Command Now, I want to check whether the textfields are empty when the user clicks send button...
I tried it in this way
if ( ae.getCommand() == send && ae.getSource()==cashpayform){
cashcheck();
}
if ( ae.getCommand() == send && ae.getSource()==accpayform){
acccheck();
}
but its not working can anyone help me thanx
When a command triggers an event the source of the event is the Command not the button so you can't physically make a distinction between a command triggered from a button press and a command triggered from a menu.
I suggest you use two different commands if you need to make a distinction between the source of the commands, they can have the same name and even ID if you make pointer comparisons.
Don't compare strings using ==
, instead use..
send.equals(ae.getCommand())
精彩评论