I'm can you help me how to count my username and password using an array.
I confuse where should I put my counter inorder to up to 5.
Hope your Positive response.....

here is my code:

String[] username=new String[5];
     String[] password=new String[5];


     public void actionPerformed(ActionEvent e)
    {
        if(e.getSource().equals(btnAdd))
        {
           
           for(int i=0;i<5;i++)
            {
                
                username[i]=txtUsername.getText();
                password[i]=txtPassword.getText();  
            }
             
                
            MyTable table=new MyTable(username,password);     
         
           
         }
        if(e.getSource().equals(btnExit)){ System.exit(0); }
    }

how to count my username and password

Sorry, I can not understand what you are trying to do.
Can you explain it again perhaps in a different way?

Are you trying to read in 5 usernames and 5 passwords and save them in an array?

I assume the user enters a name/password then clicks the btnAdd button?
If so:
Each time he does that you just need to add one name/password, not 5; but you do need to keep count of how many he has entered. For that you need a counter that is declared and initialised OUTSIDE the actionPerformed method so its value is carried forward from one call to the next. You initialise the counter to 0 when you create it, then add 1 each time you store another name/password.

Sorry, I can not understand what you are trying to do.
Can you explain it again perhaps in a different way?

Are you trying to read in 5 usernames and 5 passwords and save them in an array?

Hi Norm1,

Thank you for the reply,My problem is how can I make this program that It can only add up to 5 username and password....

example

type username:carmzy
type password: hello java

when i click addbutton this will add to jtable.

after entering 5 username and password the table will pop-up and display the username and password.

this is the output:

username       password

carmzy         hello java
john           chris
shane          task
carlo          1235
deny           jj158

I hope you can help me.thank you in advance

James has suggested a way to do that. Did you understand what he described to do?

I assume the user enters a name/password then clicks the btnAdd button?
If so:
Each time he does that you just need to add one name/password, not 5; but you do need to keep count of how many he has entered. For that you need a counter that is declared and initialised OUTSIDE the actionPerformed method so its value is carried forward from one call to the next. You initialise the counter to 0 when you create it, then add 1 each time you store another name/password.

hi JamesCherill,

thank you for the reply,but can you show me how can i do this?.and how do i display this in jtable after inputting 5 username/password?

Break the project into separate parts.
In one part get the name and pswd from the text fields, save them in an array and increment the counter.

When that is working, build the jtable.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.