I coded an application where there is 2 textfields having keylistener and a submit button with action listener.
For key and action listener, here is the coding
public void keyPressed(KeyEvent e) {
Its working fine. If i put any value in currentPaymenttext in press enter, its works. Now, (without pressing PAY button), again i change the value in currentPaymenttext and press enter, its updated with new value.
But, when i submit the form through PAY button(ActionListener), the code inside runs twice. On little bit of research i found that the number of times i change the value inside currentPaymenttext textfield in press enter, those many times submit code (i.e the code inside )runs, thus saving the same thing inside db those many number of times,
What is the mistake here?
kunal
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
> On little bit of research i found that the number of times i change the value inside currentPaymenttext textfield in press enter, those many times submit code
sounds like each click of the button adds an extra actionListener.
Kunal Lakhani
Ranch Hand
Joined: Jun 05, 2010
Posts: 609
posted
0
Thanks for your reply Michael. Yes, it adds additional ActionListener.
This was the previous coding
On removing subm.addActionListener(this);, subm.removeActionListener(this); from the if block, the problem is solved. But, i want that, if the dues >=0, then only sub button would work
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
> i want that, if the dues >=0, then only sub button would work
are you sure?
your posted code adds the actionListener to subm if(dues >= 0) is true
have you thought about enable/disable subm based on if(dues >= 0)
Kunal Lakhani
Ranch Hand
Joined: Jun 05, 2010
Posts: 609
posted
0
Thanks Michael Dunn. It works much better and is easy to use
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Is ActionListener and Key Listener related?