Projects
Projects
*;
import java.awt.*;
import
java.awt.event.ActionEvent;
import
java.awt.event.ActionListener;
import java.sql.Connection;
import
java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public Login() {
setTitle("Login");
setSize(300, 200);
setDefaultCloseOperation(JFram
e.EXIT_ON_CLOSE);
setLayout(new
GridLayout(3, 2));
add(new
JLabel("Username:"));
usernameField = new
JTextField();
add(usernameField);
add(new
JLabel("Password:"));
passwordField = new
JPasswordField();
add(passwordField);
loginButton = new
JButton("Login");
add(loginButton);
loginButton.addActionListener(thi
s);
setVisible(true);
}
@Override
public void
actionPerformed(ActionEvent e) {
String username =
usernameField.getText();
String password = new
String(passwordField.getPasswo
rd());
if (resultSet.next()) {
JOptionPane.showMessageDialo
g(this,
"Login successful!");
new POSSystem();
dispose();
} else {
JOptionPane.showMessageDialo
g(this, "Invalid username or
password.");
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}