A simple login program using swing in Java programming language.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.


My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

Please subscribe to my channel  https://www.youtube.com/channel/UCOs-lpOoIeJoh6gpJthPoGg

=================================================



Want to support my channel?

GCash Account

Jake Pomperada


09173084360



Paypal

https://paypal.me/jakerpomperada



Patreon

https://www.patreon.com/jakerpomperada




Thank you very much for your support.

Program Listing
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JOptionPane;

/**
 *
 * Simple Login Using Swing in Java
 *
 * @version 1.0 from 09/07/2022
 * @Jake Pomperada
 */

public class LoginDemo extends JFrame {
  /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
// start attributes
  private JLabel lblUsername = new JLabel();
  private JLabel lblPassword = new JLabel();
  private JTextField txtUSername = new JTextField();
  private JTextField txtPassword = new JTextField();
  private JButton bOK = new JButton();
  private JButton btnCancel = new JButton();
  // end attributes
  
  public LoginDemo() { 
    // Frame-Init
    super();
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    int frameWidth = 289; 
    int frameHeight = 205;
    setSize(frameWidth, frameHeight);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (d.width - getSize().width) / 2;
    int y = (d.height - getSize().height) / 2;
    setLocation(x, y);
    setTitle("LoginDemo");
    setResizable(false);
    Container cp = getContentPane();
    cp.setLayout(null);
    // start components
    btnCancel.setBounds(184, 120, 83, 25);
    btnCancel.setText("Cancel");
    btnCancel.setMargin(new Insets(2, 2, 2, 2));
    btnCancel.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent evt) { 
        btnCancel_ActionPerformed(evt);
      }
    });
    btnCancel.setMnemonic(KeyEvent.VK_A);
    cp.add(btnCancel);
    bOK.setBounds(104, 120, 75, 25);
    bOK.setText("OK");
    bOK.setMargin(new Insets(2, 2, 2, 2));
    bOK.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent evt) { 
        bOK_ActionPerformed(evt);
      }
    });
    cp.add(bOK);
    txtUSername.setBounds(104, 24, 161, 25);
    cp.add(txtUSername);
    lblUsername.setBounds(8, 24, 89, 25);
    lblUsername.setText("Username");
    cp.add(lblUsername);
    
    lblPassword.setBounds(8, 72, 89, 25);
    lblPassword.setText("Password");
    cp.add(lblPassword);
    txtPassword.setBounds(104, 72, 161, 25);
    cp.add(txtPassword);
    // end components
    
    setVisible(true);
  }
  
  // start methods
  
  public static void main(String[] args) {
    new LoginDemo();
  }
  public void bOK_ActionPerformed(ActionEvent evt) {
    String userName = txtUSername.getText();
    String passWord = txtPassword.getText();
    
    if(userName.equals("admin") && passWord.equals("123"))
      JOptionPane.showMessageDialog(this, "Login successful");
    else {
      JOptionPane.showMessageDialog(this, "Login failed");
    }
    
  }

  public void btnCancel_ActionPerformed(ActionEvent evt) {
    System.exit(0);
  }
}