import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class LoginApp {
public static void main(String[] args) {
// Create Frame
JFrame frame = new JFrame("Login Window");
frame.setSize(350, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
// Create Panel
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(3, 2, 10, 10));
// Components
JLabel userLabel = new JLabel("Username:");
JTextField userField = new JTextField();
JLabel passLabel = new JLabel("Password:");
JPasswordField passField = new JPasswordField();
JButton submitBtn = new JButton("Submit");
// Add components to panel
panel.add(userLabel);
panel.add(userField);
panel.add(passLabel);
panel.add(passField);
panel.add(new JLabel()); // empty space
panel.add(submitBtn);
frame.add(panel);
frame.setVisible(true);
// Button Action
submitBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String username = userField.getText();
String password = new String(passField.getPassword());
// You can add validation here if needed
if (!username.isEmpty() && !password.isEmpty()) {
frame.dispose(); // Close login window
// New Window
JFrame successFrame = new JFrame("Success");
successFrame.setSize(300, 150);
successFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
successFrame.setLocationRelativeTo(null);
JLabel successLabel = new JLabel("Submitted Successfully!", SwingConstants.CENTER);
successLabel.setFont(new Font("Arial", Font.BOLD, 16));
successFrame.add(successLabel);
successFrame.setVisible(true);
} else {
JOptionPane.showMessageDialog(frame, "Please enter username and password");
}
}
});
}
}
Subscribey channel for such content.
On this page of the site you can watch the video online Code in the description|| Java Swing. Login window using Java swing. with a duration of hours minute second in good quality, which was uploaded by the user 60 Second Syntax 28 February 2026, share the link with friends and acquaintances, this video has already been watched times on youtube and it was liked by 0 viewers. Enjoy your viewing!