Is it sth like this
int grades[][] = {} ?
Printable View
Is it sth like this
int grades[][] = {} ?
I manage to figure out
Code:String table[][] = {{"Vani", "Vicknes", "Kamala", "Vimal", "Bala"},
{"Vani1234", "Vick1234", "Kam1234", "Vimal90", "Bala62"}};
Now how am i to check against the array table with the login id and password i have keyed in to validate that its correct?
Code:import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class AccountLogin extends JFrame
{
String table[][] = {{"Vani", "Vicknes", "Kamala", "Vimal", "Bala"},
{"Vani1234", "Vick1234", "Kam1234", "Vimal90", "Bala62"}};
// String array2[] = {"Vani1234", "Vick1234", "Kam1234", "Vimal90", "Bala62"};
private JLabel lblAccountId;
private JTextField txtAccountId;
private JLabel lblPassword;
private JTextField txtPassword;
private JButton btnLogin;
private JLabel lblOutPut;
// private char echochar = '*';
public AccountLogin()
{
lblAccountId = new JLabel("Account ID");
txtAccountId = new JTextField(15);
lblPassword = new JLabel("Password");
txtPassword = new JTextField(10);
//txtPassword.setEchoChar('*');
btnLogin = new JButton("Login");
btnLogin.addActionListener(new MyListener());
lblOutPut = new JLabel();
JPanel panel = (JPanel)getContentPane();
panel.setLayout(new FlowLayout());
panel.add(lblAccountId);
panel.add(txtAccountId);
panel.add(lblPassword);
panel.add(txtPassword);
panel.add(btnLogin);
panel.add(lblOutPut);
setSize(300,200);
setTitle("Vanisri");
setVisible(true);
}
private class MyListener implements ActionListener{
public void actionPerformed(ActionEvent e){
lblOutPut.setText("Welcome Vani");
}
}
public static void main(String[] args)
{
new AccountLogin();
}
}
use two loops to scan [][] array ;)
Code:for(...)
{
for(...){}
}
Can u give me an example on how to do it?
Given your table[][] matrix, a possible user name and a password the following simple method checks whether or not the user name exists and if the password is valid:
As you can see a single loop can do it: it checks all usernames until one is found; next it checks the corresponding password and returns true if they match, false otherwise.Code:public boolean check(String user, String password) {
for (int i= 0; i < table[0].length; i++)
if (table[0][i].equals(user))
return table[1][i].equals(password);
return false;
}
kind regards,
Jos