0% found this document useful (0 votes)
23 views6 pages

Top

The document contains code to create a login page and registration page using Java Swing. The login page code creates a frame with labels, text fields, and buttons for a username and password. It retrieves the entered username and password on button click and displays them. The registration page code creates a frame with labels, text fields, combo boxes, and a button to collect and display first name, last name, gender, and date of birth fields. It retrieves and prints the entered registration details on button click.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views6 pages

Top

The document contains code to create a login page and registration page using Java Swing. The login page code creates a frame with labels, text fields, and buttons for a username and password. It retrieves the entered username and password on button click and displays them. The registration page code creates a frame with labels, text fields, combo boxes, and a button to collect and display first name, last name, gender, and date of birth fields. It retrieves and prints the entered registration details on button click.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

7)program to create login page

import javax.swing.*;

import java.awt.event.*;

public class user {

public sta c void main(String[] args) {

JFrame f=new JFrame("Password Field Example");

final JLabel label = new JLabel();

label.setBounds(20,150, 200,50);

final JPasswordField value = new JPasswordField();

value.setBounds(100,75,100,30);

JLabel l1=new JLabel("Username:");

l1.setBounds(20,20, 80,30);

JLabel l2=new JLabel("Password:");

l2.setBounds(20,75, 80,30);

JBu on b = new JBu on("Login");

b.setBounds(100,120, 80,30);

final JTextField text = new JTextField();

text.setBounds(100,20, 100,30);

f.add(value); f.add(l1); f.add(label); f.add(l2); f.add(b); f.add(text);

f.setSize(300,300);

f.setLayout(null);

f.setVisible(true);

b.addAc onListener(new Ac onListener() {

public void ac onPerformed(Ac onEvent e) {

String data = "Username " + text.getText();

data += ", Password: "

+ new String(value.getPassword());

label.setText(data);

}
});

Output:

8)program to create registra on page

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class user extends JFrame {

private JTextField firstNameField, lastNameField, dobField;

private JComboBox<String> genderComboBox;

private JBu on registerBu on;

public user() {

setTitle("Registra on Form");
setSize(300, 200);

setDefaultCloseOpera on(EXIT_ON_CLOSE);

setLoca onRela veTo(null);

JPanel panel = new JPanel();

panel.setLayout(new GridLayout(5, 2));

JLabel firstNameLabel = new JLabel("First Name:");

firstNameField = new JTextField();

JLabel lastNameLabel = new JLabel("Last Name:");

lastNameField = new JTextField();

JLabel genderLabel = new JLabel("Gender:");

String[] genders = {"Male", "Female", "Other"};

genderComboBox = new JComboBox<>(genders);

JLabel dobLabel = new JLabel("Date of Birth (YYYY-MM-DD):");

dobField = new JTextField();

JLabel emptyLabel = new JLabel(); // Empty label for layout purposes

registerBu on = new JBu on("Register");

registerBu on.addAc onListener(new Ac onListener() {

public void ac onPerformed(Ac onEvent e) {

register();

});

panel.add(firstNameLabel);

panel.add(firstNameField);

panel.add(lastNameLabel);

panel.add(lastNameField);

panel.add(genderLabel);
panel.add(genderComboBox);

panel.add(dobLabel);

panel.add(dobField);

panel.add(emptyLabel);

panel.add(registerBu on);

add(panel);

setVisible(true);

private void register() {

String firstName = firstNameField.getText();

String lastName = lastNameField.getText();

String gender = (String) genderComboBox.getSelectedItem();

String dob = dobField.getText();

// Perform registra on logic here

System.out.println("Registered: " + firstName + " " + lastName + ", Gender: " + gender + ", Date of
Birth: " + dob);

new user();

You might also like