I have created a login Frame - Login Frame(1) using Java Swing where user authentication also happen.
It looks like this:
So, if a user puts wrong email id / password, it should show a Message Dialog. That's why here I use:
JOptionPane.showMessageDialog( this,"plese enter correct id/password")
But it is showing an error..
Login.addActionListener((e) -> {
ArrayList<Registration> list0;
list0=UserDataReadWriteFromFile.readDataFromFile();
int idpos=Search.searchId(tuid.getText().trim());
if(idpos >=0){
String ueid=tuid.getText().trim();
String uupass=tpass.getText().trim();
if(ueid.equals(list0.get(idpos).getId())&& uupass.equals(list0.get(idpos).getPassword())){
new SearchDisp(idpos);
}
else
JOptionPane.showMessageDialog( this,"plese enter correct id/password");
}
});
What component should I use in JOptionPane.showMessageDialog()
?
here is the code of my Login frame.In this code with the Login Button I have added Action Listener,which is written in the above code i have asked.
public class LoginFrame{
public LoginFrame() {
JLabel uid, upass;
JTextField tuid;
JPasswordField tpass;
JButton Login;
JFrame frame = new JFrame("Login");
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.setLayout(null);
JLabel background = new JLabel(new ImageIcon(
"C:\\Users\\Tousif\\Desktop\\Login.jpg"));
frame.setContentPane(background);
uid = new JLabel("Email Id");
uid.setBounds(60, 50, 120, 25);
frame.add(uid);
tuid = new JTextField(20);
tuid.setBounds(120, 50, 150, 24);
frame.add(tuid);
upass = new JLabel("Password");
upass.setBounds(53, 80, 120, 25);
frame.add(upass);
tpass = new JPasswordField(20);
tpass.setBounds(120, 80, 150, 24);
frame.add(tpass);
Login = new JButton("Login");
Login.setBounds(150, 110, 80, 25);
frame.add(Login);
frame.setSize(370, 216);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] arg) {
new LoginFrame();
}
}