Why isn't my login system working?

Sigchi4life
Category:
Other
Price: $5 USD

Question description

package me.daniel.Practice;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Login {
public static void main(String[] args) {
JFrame frame = new JFrame("Password Login System");
frame.setSize(400, 100);
frame.setResizable(false);
frame.setVisible(true);
frame.setBackground(Color.WHITE);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
JPanel panel = new JPanel(new GridBagLayout());
JLabel label = new JLabel("Enter Password: ");
JLabel label1 = new JLabel("Enter Username: ");
JButton button = new JButton("Sign In");
JPasswordField pass = new JPasswordField(10);
JPasswordField user = new JPasswordField(10);
GridBagConstraints c = new GridBagConstraints();
pass.setEchoChar('*');
user.setEchoChar((char) 0);
user.addActionListener(new AL());
pass.addActionListener(new AL1());
button.addActionListener(new butt());
c.gridx = 0;
c.gridy = 0;
c.insets = new Insets(30, 200, 0, 0);
panel.add(button, c);
c.gridx = 0;
c.gridy = 0;
c.insets = new Insets(0, 0, 20, 220);
panel.add(label1, c);
c.gridx = 0;
c.gridy = 0;
c.insets = new Insets(40, 0, 0, 220);
panel.add(label, c);
c.gridx = 0;
c.gridy = 0;
c.insets = new Insets(0, 0, 20, 0);
panel.add(user, c);
c.gridx = 0;
c.gridy = 0;
c.insets = new Insets(40, 0, 0, 0);
panel.add(pass, c);
frame.add(panel);
frame.validate();
}
public static String username = "danichee";
static class AL implements ActionListener {
public void actionPerformed(ActionEvent e) {
JPasswordField input = (JPasswordField) e.getSource();
char[] user = input.getPassword();
String u = new String(user);
}
}
public static String password = "daniel";
static class AL1 implements ActionListener {
public void actionPerformed(ActionEvent e) {
JPasswordField input = (JPasswordField) e.getSource();
char[] passy = input.getPassword();
String p = new String(passy);
}
}
static class butt implements ActionListener {
public void actionPerformed(ActionEvent e) {
AL al = new AL();
AL1 al1 = new AL1();
if (al.equals(username) && al1.equals(password)) {
JOptionPane.showMessageDialog(null, "Correct!");
} else {
JOptionPane.showMessageDialog(null, "Incorrect!");
}
}
}
}

Studypool has helped 1,244,100 students
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1831 tutors are online

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors