Комментарии:
//**************************************************
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);
}
}
//**************************************************
❤
Ответитьbro is gonna save my uni degree
ОтветитьThanks for your awesome content ❤
ОтветитьReally really good job, thank you !
Ответить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?
ОтветитьLove you Bro.
ОтветитьVery nice :D
ОтветитьWro Code
ОтветитьNice video, well done, thank you for sharing it :)
ОтветитьI think instead of ambiguously circuitous welcomlabel with new comstructor
jOptionPane might be more effacacious to break down some some complexity
hiii
Ответитьcan you tell me how we can add icon on taskbar when that application is running in java.
ОтветитьCould you add 2FA?
Ответить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.
this is a real chad. I hope to meet you one day, mr. bro
Ответить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) .
ОтветитьTHANksss again bro!!!!
Ответить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
Ответитьgogogog🥵
Ответитьthanks Bro! it really helps me a lot!
Ответить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
Ответить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
ОтветитьThank you
Ответитьi just love you Bro 💖💖
Ответить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 (:
ОтветитьBroo, thank you very much, this is exactly what I needed.
ОтветитьHi Bro Code! How do I import Hash map?
ОтветитьThanks sir!
ОтветитьA question, when you created Login page login page = new Loginpage, in the main, would it be possible to put that code in IDandPassword
Ответитьjust a comment so this go pop
ОтветитьThank you! Simply but awesome!
Ответить<3
ОтветитьComment comment=new comment ();🙂
ОтветитьComment
Ответить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?
-
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?
ОтветитьThank you so much! , I made it
ОтветитьThis video is so helpful. Thank you.
Ответитьhow to add background image ?
Ответить🥰
ОтветитьI am highly offended you used the word "bro code". I identify as a cat, so please next time include "P%÷=% Code".
ОтветитьAll time best coding video Ever 🌟
Ответитьthank you so much, after watching your videos I more interesting to practice Java .... Cheers
Ответитьhello bro, do u know how to add a login attempt?
ОтветитьThank bro
ОтветитьPlease real-time apps
Ответить👏👏👏
Ответить