|
@ -2,6 +2,8 @@ import javax.swing.*; |
|
|
import java.awt.event.ActionEvent; |
|
|
import java.awt.event.ActionEvent; |
|
|
import java.awt.event.ActionListener; |
|
|
import java.awt.event.ActionListener; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
import java.awt.event.KeyEvent; |
|
|
|
|
|
import java.awt.event.KeyListener; |
|
|
|
|
|
|
|
|
public class LoginGUI extends JFrame implements ActionListener { |
|
|
public class LoginGUI extends JFrame implements ActionListener { |
|
|
private JTextField usernameField; |
|
|
private JTextField usernameField; |
|
@ -35,22 +37,26 @@ public class LoginGUI extends JFrame implements ActionListener { |
|
|
loginButton.addActionListener(this); |
|
|
loginButton.addActionListener(this); |
|
|
add(loginButton); |
|
|
add(loginButton); |
|
|
|
|
|
|
|
|
|
|
|
getRootPane().setDefaultButton(loginButton); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void actionPerformed(ActionEvent e) { |
|
|
public void actionPerformed(ActionEvent e) { |
|
|
if (e.getSource() == loginButton) { |
|
|
|
|
|
String username = usernameField.getText(); |
|
|
|
|
|
String password = new String(passwordField.getPassword()); |
|
|
|
|
|
|
|
|
if (e.getSource() == loginButton) { |
|
|
|
|
|
login(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void login() { |
|
|
|
|
|
String username = usernameField.getText(); |
|
|
|
|
|
String password = new String(passwordField.getPassword()); |
|
|
|
|
|
|
|
|
if (authenticateUser(username, password)) { |
|
|
|
|
|
|
|
|
if (authenticateUser(username, password)) { |
|
|
JOptionPane.showMessageDialog(this, "Login successful!"); |
|
|
JOptionPane.showMessageDialog(this, "Login successful!"); |
|
|
// Perform actions after successful login |
|
|
// Perform actions after successful login |
|
|
} else { |
|
|
|
|
|
|
|
|
} else { |
|
|
JOptionPane.showMessageDialog(this, "Invalid username or password", "Login Error", JOptionPane.ERROR_MESSAGE); |
|
|
JOptionPane.showMessageDialog(this, "Invalid username or password", "Login Error", JOptionPane.ERROR_MESSAGE); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -68,6 +74,21 @@ public class LoginGUI extends JFrame implements ActionListener { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private class EnterKeyListener implements KeyListener { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void keyTyped(KeyEvent e) {} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void keyPressed(KeyEvent e) { |
|
|
|
|
|
if (e.getKeyCode() == KeyEvent.VK_ENTER) { |
|
|
|
|
|
login(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void keyReleased(KeyEvent e) {} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
public static void main(String[] args) { |
|
|
SwingUtilities.invokeLater(() -> { |
|
|
SwingUtilities.invokeLater(() -> { |
|
|
LoginGUI loginGUI = new LoginGUI(); |
|
|
LoginGUI loginGUI = new LoginGUI(); |
|
|