Java login system ‍

Java login system ‍

Bro Code

4 года назад

302,657 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Bro Code
Bro Code - 06.06.2020 22:44

//**************************************************
public class Main {

public static void main(String[] args) {

IDandPasswords idandPasswords = new IDandPasswords();

LoginPage loginPage = new LoginPage(idandPasswords.getLoginInfo());

}
}
//**************************************************
public class IDandPasswords {

HashMap<String,String> logininfo = new HashMap<String,String>();

IDandPasswords(){

logininfo.put("Bro","pizza");
logininfo.put("Brometheus","PASSWORD");
logininfo.put("BroCode","abc123");
}

public HashMap getLoginInfo(){
return logininfo;
}
}
//**************************************************
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;

public class LoginPage implements ActionListener{

JFrame frame = new JFrame();
JButton loginButton = new JButton("Login");
JButton resetButton = new JButton("Reset");
JTextField userIDField = new JTextField();
JPasswordField userPasswordField = new JPasswordField();
JLabel userIDLabel = new JLabel("userID:");
JLabel userPasswordLabel = new JLabel("password:");
JLabel messageLabel = new JLabel();
HashMap<String,String> logininfo = new HashMap<String,String>();

LoginPage(HashMap<String,String> loginInfoOriginal){

logininfo = loginInfoOriginal;

userIDLabel.setBounds(50,100,75,25);
userPasswordLabel.setBounds(50,150,75,25);

messageLabel.setBounds(125,250,250,35);
messageLabel.setFont(new Font(null,Font.ITALIC,25));

userIDField.setBounds(125,100,200,25);
userPasswordField.setBounds(125,150,200,25);

loginButton.setBounds(125,200,100,25);
loginButton.setFocusable(false);
loginButton.addActionListener(this);

resetButton.setBounds(225,200,100,25);
resetButton.setFocusable(false);
resetButton.addActionListener(this);

frame.add(userIDLabel);
frame.add(userPasswordLabel);
frame.add(messageLabel);
frame.add(userIDField);
frame.add(userPasswordField);
frame.add(loginButton);
frame.add(resetButton);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(420,420);
frame.setLayout(null);
frame.setVisible(true);

}

@Override
public void actionPerformed(ActionEvent e) {

if(e.getSource()==resetButton) {
userIDField.setText("");
userPasswordField.setText("");
}

if(e.getSource()==loginButton) {

String userID = userIDField.getText();
String password = String.valueOf(userPasswordField.getPassword());

if(logininfo.containsKey(userID)) {
if(logininfo.get(userID).equals(password)) {
messageLabel.setForeground(Color.green);
messageLabel.setText("Login successful");
frame.dispose();
WelcomePage welcomePage = new WelcomePage(userID);
}
else {
messageLabel.setForeground(Color.red);
messageLabel.setText("Wrong password");
}

}
else {
messageLabel.setForeground(Color.red);
messageLabel.setText("username not found");
}
}
}
}
//**************************************************
import java.awt.*;
import javax.swing.*;

public class WelcomePage {

JFrame frame = new JFrame();
JLabel welcomeLabel = new JLabel("Hello!");

WelcomePage(String userID){

welcomeLabel.setBounds(0,0,200,35);
welcomeLabel.setFont(new Font(null,Font.PLAIN,25));
welcomeLabel.setText("Hello "+userID);

frame.add(welcomeLabel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(420, 420);
frame.setLayout(null);
frame.setVisible(true);
}
}
//**************************************************

Ответить
40_Ojas Kaushik_VIIA
40_Ojas Kaushik_VIIA - 18.10.2023 18:23

Ответить
RA—ONE
RA—ONE - 18.10.2023 09:12

Ответить
LethalLizard_
LethalLizard_ - 07.10.2023 04:38

bro is gonna save my uni degree

Ответить
Lahik Ahmed
Lahik Ahmed - 01.10.2023 18:54

Thanks for your awesome content ❤

Ответить
Ludovic Bocquet
Ludovic Bocquet - 18.09.2023 12:53

Really really good job, thank you !

Ответить
Prajwal Pramod
Prajwal Pramod - 06.09.2023 03:28

Let's say I want to create a system which can detect a wrong password as soon as I type in the required number of characters (without me pressing any button). How would I do that?

Ответить
AKASH DATTA
AKASH DATTA - 29.08.2023 21:41

Love you Bro.

Ответить
Dawid Kaczka
Dawid Kaczka - 26.08.2023 10:21

Very nice :D

Ответить
Aron Abraham
Aron Abraham - 06.08.2023 00:35

Wro Code

Ответить
Rixtronix LAB
Rixtronix LAB - 25.07.2023 05:03

Nice video, well done, thank you for sharing it :)

Ответить
NEO
NEO - 11.07.2023 12:08

I think instead of ambiguously circuitous welcomlabel with new comstructor

jOptionPane might be more effacacious to break down some some complexity

Ответить
Ania Nowak
Ania Nowak - 25.06.2023 23:52

hiii

Ответить
Anjali Yadav
Anjali Yadav - 26.05.2023 09:08

can you tell me how we can add icon on taskbar when that application is running in java.

Ответить
Gürkan
Gürkan - 26.04.2023 10:59

i love your videos brooo
your videos are so clear and short, essential

Ответить
nee aldon2
nee aldon2 - 24.04.2023 00:55

Could you add 2FA?

Ответить
zstar
zstar - 14.04.2023 03:28

Yo just wanna say that GOD loved the world so much he sent his only begotten
son Jesus to die a brutal death for us so that we can have eternal life
and we can all accept this amazing gift this by simply believing in him (Jesus) asking for the forgiveness of your sins
and forming a relationship with heavenly father.

Ответить
Ytriu Miliardaru
Ytriu Miliardaru - 02.04.2023 19:24

this is a real chad. I hope to meet you one day, mr. bro

Ответить
cud
cud - 21.03.2023 16:29

thanks so much! although i hv a little problem, wherein my welcome page tab isn't displaying, overall, this tutorial is exceptional and helpful for me who's a beginner in java (GUI) .

Ответить
gRIZZly GAMING
gRIZZly GAMING - 10.03.2023 11:06

THANksss again bro!!!!

Ответить
WAVIE FF
WAVIE FF - 04.03.2023 02:08

guys again add * to import everyting like javax.swing.* java.util.* it helps to not tpe alot of import texts and its good if ou are lazy hehe

Ответить
Axele Nandoh
Axele Nandoh - 03.03.2023 19:31

gogogog🥵

Ответить
Gloria
Gloria - 28.02.2023 17:10

thanks Bro! it really helps me a lot!

Ответить
Shikhar Khare
Shikhar Khare - 14.02.2023 07:26

Hi, great video, very well explained, could you pls help me out a little, In this video you are doing many imports ,but in my eclipse the import option is not coming for listener method

Ответить
Kevin Us
Kevin Us - 13.02.2023 03:37

I have assignment to creat log in page with username and password and button login and back button. Can I use the code in this video for Java fx and builder scene

Ответить
ahmad IQ
ahmad IQ - 08.02.2023 18:04

Thank you

Ответить
Meryam Eddaif
Meryam Eddaif - 07.02.2023 22:14

i just love you Bro 💖💖

Ответить
Dániel Nagy
Dániel Nagy - 04.02.2023 15:15

Hey Bro, I messed up something with the messageLabel but no idea where. "Wrong password" only appears if I entered firstly the correct info, then the wrong..every Bros help is very much appreciated (:

Ответить
samuel logod
samuel logod - 02.02.2023 04:30

Broo, thank you very much, this is exactly what I needed.

Ответить
J
J - 02.02.2023 00:31

Hi Bro Code! How do I import Hash map?

Ответить
MICEV Mares
MICEV Mares - 02.02.2023 00:02

Thanks sir!

Ответить
I am nobody
I am nobody - 28.01.2023 09:31

A question, when you created Login page login page = new Loginpage, in the main, would it be possible to put that code in IDandPassword

Ответить
17 50
17 50 - 26.01.2023 00:03

just a comment so this go pop

Ответить
András Fejes
András Fejes - 25.01.2023 00:05

Thank you! Simply but awesome!

Ответить
Seener
Seener - 22.01.2023 14:28

<3

Ответить
tatakae tatakae
tatakae tatakae - 27.12.2022 03:21

Comment comment=new comment ();🙂

Ответить
tatakae tatakae
tatakae tatakae - 27.12.2022 03:21

Comment

Ответить
Gumban Nikki
Gumban Nikki - 19.12.2022 11:28

good day sir, I would like to ask how to put background color or image in the log in page. do you have a tutorial for that?
-

Ответить
james Lindsay
james Lindsay - 06.12.2022 16:49

quick question, why not just make the IDandPasswords class static, that way you won't have to make an instance of it in the main method?

Ответить
tyshaunprincejunio
tyshaunprincejunio - 29.11.2022 10:13

Thank you so much! , I made it

Ответить
Luthando Leeuw
Luthando Leeuw - 24.11.2022 10:46

This video is so helpful. Thank you.

Ответить
Wong yuyang
Wong yuyang - 23.11.2022 11:00

how to add background image ?

Ответить
Henry Müller
Henry Müller - 20.11.2022 12:13

🥰

Ответить
Spawn
Spawn - 15.11.2022 19:42

I am highly offended you used the word "bro code". I identify as a cat, so please next time include "P%÷=% Code".

Ответить
your time pass
your time pass - 10.11.2022 05:23

All time best coding video Ever 🌟

Ответить
Kang Ody
Kang Ody - 08.11.2022 19:32

thank you so much, after watching your videos I more interesting to practice Java .... Cheers

Ответить
tyarlsss
tyarlsss - 25.10.2022 18:02

hello bro, do u know how to add a login attempt?

Ответить
Khaled Aini
Khaled Aini - 22.10.2022 21:56

Thank bro

Ответить
Mauana West
Mauana West - 22.10.2022 06:58

Please real-time apps

Ответить
Caleb Chinayan
Caleb Chinayan - 20.10.2022 15:58

👏👏👏

Ответить