Skip to content

Instantly share code, notes, and snippets.

@Sabareh
Created March 22, 2023 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sabareh/f34e2c81804465df3005efd471b645d7 to your computer and use it in GitHub Desktop.
Save Sabareh/f34e2c81804465df3005efd471b645d7 to your computer and use it in GitHub Desktop.
A basic login and registration form with fields for name, email, password, and confirm password. The form uses Java AWT/Swing components and includes event listeners for the login and registration buttons. Note that the login and registration functionality still needs to be implemented.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LoginRegistrationForm extends JFrame implements ActionListener {
private JLabel titleLabel, nameLabel, emailLabel, passwordLabel, confirmPasswordLabel;
private JTextField nameField, emailField;
private JPasswordField passwordField, confirmPasswordField;
private JButton loginButton, registerButton;
public LoginRegistrationForm() {
super("Login and Registration Form");
setSize(400, 300);
setLocationRelativeTo(null);
setLayout(new BorderLayout());
// Create the title label
titleLabel = new JLabel("Welcome to My Business");
titleLabel.setHorizontalAlignment(JLabel.CENTER);
add(titleLabel, BorderLayout.NORTH);
// Create the login and registration panels
JPanel loginPanel = new JPanel(new GridLayout(3, 2));
JPanel registrationPanel = new JPanel(new GridLayout(4, 2));
add(loginPanel, BorderLayout.CENTER);
add(registrationPanel, BorderLayout.SOUTH);
// Create the login fields
nameLabel = new JLabel("Name:");
emailLabel = new JLabel("Email:");
passwordLabel = new JLabel("Password:");
nameField = new JTextField();
emailField = new JTextField();
passwordField = new JPasswordField();
loginButton = new JButton("Login");
loginButton.addActionListener(this);
loginPanel.add(nameLabel);
loginPanel.add(nameField);
loginPanel.add(emailLabel);
loginPanel.add(emailField);
loginPanel.add(passwordLabel);
loginPanel.add(passwordField);
loginPanel.add(loginButton);
// Create the registration fields
confirmPasswordLabel = new JLabel("Confirm Password:");
confirmPasswordField = new JPasswordField();
registerButton = new JButton("Register");
registerButton.addActionListener(this);
registrationPanel.add(nameLabel);
registrationPanel.add(nameField);
registrationPanel.add(emailLabel);
registrationPanel.add(emailField);
registrationPanel.add(passwordLabel);
registrationPanel.add(passwordField);
registrationPanel.add(confirmPasswordLabel);
registrationPanel.add(confirmPasswordField);
registrationPanel.add(registerButton);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == loginButton) {
// TODO: Implement login functionality
} else if (e.getSource() == registerButton) {
// TODO: Implement registration functionality
}
}
public static void main(String[] args) {
new LoginRegistrationForm();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment