Jump to content

Java code to separately enter numbers using the same set of jbuttons?

Shammikit

i need to have two textfields to enter pin and account number. i will be entering these numbers using the pin pad i have made using jbuttons. but im only able to enter to one field.i there some code to distinguish between the 2 textfield.like on mouse click on to the relevant textfield input number there.

Link to comment
Share on other sites

Link to post
Share on other sites

You probably did just hardcode to which text input your numpad is adding numbers, instead of it make yourself a variable that will hold last focused text input, set it to null, and then set this variable whenever you focus text input (one or the another) and set it back to null when it blurs (looses focus), you would need listeners for that.

I guess you will always loose focus after you switch to your numpad so that blur thing you can omit.

 

After that change your buttons to modify a text input in the variable you just made. Always check if it is not null before you try to modify it's contents.

Link to comment
Share on other sites

Link to post
Share on other sites

You should make one form for the account number, and then another window which pops up for the PIN. That's the way banking programs do it.

Link to comment
Share on other sites

Link to post
Share on other sites

  • 4 weeks later...

I know this is a bit old, but you could use a int/boolean and a focus listener, something like:

 

int active = 1;

textField1.addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {
                active = 1;
            }
        });

textField2.addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {
                active = 2;
            }
        });

 

And then check the value of active each time you receive a new number check it against the active value to see where to put it.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×