Question
Can you add a Create ID button on the login page and have it pop up 2 text fields: Authorization Token & Password? ---------------------------------------------------- package
Can you add a "Create ID" button on the login page and have it pop up 2 text fields: Authorization Token & Password?
----------------------------------------------------
package grades;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Login_S {
private JFrame frame;
private JPasswordField txtPassword;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Login_S window = new Login_S();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Login_S() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JLabel lblNewLabel = new JLabel("LOGIN");
lblNewLabel.setBounds(185, 21, 46, 22);
frame.getContentPane().add(lblNewLabel);
JLabel lblUsername = new JLabel("Username");
lblUsername.setBounds(70, 71, 66, 14);
frame.getContentPane().add(lblUsername);
JLabel lblPassword = new JLabel("Password");
lblPassword.setBounds(70, 138, 79, 14);
frame.getContentPane().add(lblPassword);
JTextArea txtUsername = new JTextArea();
txtUsername.setBounds(214, 66, 185, 22);
frame.getContentPane().add(txtUsername);
txtPassword = new JPasswordField();
txtPassword.setBounds(212, 130, 187, 22);
frame.getContentPane().add(txtPassword);
//login button code.
JButton btnLogin = new JButton("Login");
btnLogin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
GradeDB gradeDB = new GradeDB();
String password = Encryptor.encrypt(txtPassword.getText());
String username = txtUsername.getText();
// check loggin success or fail
if(password.equals(gradeDB.retrievePassword(username)))
{
JOptionPane.showMessageDialog(frame," you are logged in successfuly");
}
else
{
JOptionPane.showMessageDialog(frame, "invalid username or password");
}
}
});
btnLogin.setBounds(93, 186, 89, 23);
frame.getContentPane().add(btnLogin);
//logout button code
JButton btnLogout = new JButton("Logout");
btnLogout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame = new JFrame("Exit");
if(JOptionPane.showConfirmDialog(frame,"Confirm if you want to exit","Login Systems",JOptionPane.YES_NO_OPTION)==JOptionPane.YES_NO_OPTION){
System.exit(1);
}
}
});
btnLogout.setBounds(292, 186, 89, 23);
frame.getContentPane().add(btnLogout);
//reset button code
JButton btnReset = new JButton("Reset");
btnReset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
txtUsername.setText(null);
txtPassword.setText(null);
}
});
btnReset.setBounds(193, 186, 89, 23);
frame.getContentPane().add(btnReset);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started