Untitled
unknown
java
2 years ago
8.2 kB
6
Indexable
import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
class FrameOfLogin extends JFrame {
JButton Forget_Password_Button;
JLabel label_of_wrong_password_of_LGB;
FrameOfLogin() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(1366, 768);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(1366, 768);
JPanel outer_panel_of_LGB = new JPanel();
outer_panel_of_LGB.setBackground(new java.awt.Color(0, 0, 51));
outer_panel_of_LGB.setLayout(null);
add(outer_panel_of_LGB);
JPanel inner_panel_of_LGB = new JPanel();
inner_panel_of_LGB.setBounds(520, 150, 330, 440);
inner_panel_of_LGB.setBackground(new java.awt.Color(0, 0, 90));
inner_panel_of_LGB.setLayout(null);
outer_panel_of_LGB.add(inner_panel_of_LGB);
JPanel innerOfInner_panel_of_LGB = new JPanel();
innerOfInner_panel_of_LGB.setBounds(30, 60, 270, 60);
innerOfInner_panel_of_LGB.setBackground(new java.awt.Color(0, 0, 51));
innerOfInner_panel_of_LGB.setLayout(null);
inner_panel_of_LGB.add(innerOfInner_panel_of_LGB);
JLabel title_LOG_IN = new JLabel("LOG IN");
title_LOG_IN.setBounds(0, 0, 270, 60);
title_LOG_IN.setHorizontalAlignment(SwingConstants.CENTER);
title_LOG_IN.setBorder(BorderFactory.createTitledBorder(null, "", TitledBorder.DEFAULT_JUSTIFICATION,
TitledBorder.DEFAULT_JUSTIFICATION, new java.awt.Font("Consolas", 1, 24), new java.awt.Color(204, 255, 0)));
title_LOG_IN.setForeground(new java.awt.Color(153, 255, 0));
title_LOG_IN.setFont(new java.awt.Font("Consolas", 1, 24));
innerOfInner_panel_of_LGB.add(title_LOG_IN);
JTextField username_box_of_LGB = new JTextField("username");
username_box_of_LGB.setBounds(130, 180, 170, 30);
username_box_of_LGB.setBackground(new java.awt.Color(0, 0, 51));
username_box_of_LGB.setFont(new java.awt.Font("Consolas", 0, 14));
username_box_of_LGB.setForeground(new java.awt.Color(153, 255, 0));
inner_panel_of_LGB.add(username_box_of_LGB);
JLabel label_of_username_box_of_LGB = new JLabel("Username :");
label_of_username_box_of_LGB.setBounds(40, 180, 80, 30);
label_of_username_box_of_LGB.setFont(new java.awt.Font("Consolas", 1, 14));
label_of_username_box_of_LGB.setForeground(new java.awt.Color(255, 0, 0));
inner_panel_of_LGB.add(label_of_username_box_of_LGB);
JPasswordField password_box_of_LGB = new JPasswordField("username");
password_box_of_LGB.setBounds(130, 230, 170, 30);
password_box_of_LGB.setBackground(new java.awt.Color(0, 0, 51));
password_box_of_LGB.setFont(new java.awt.Font("Consolas", 0, 14));
password_box_of_LGB.setForeground(new java.awt.Color(153, 255, 0));
inner_panel_of_LGB.add(password_box_of_LGB);
JLabel label_of_password_box_of_LGB = new JLabel("Password :");
label_of_password_box_of_LGB.setBounds(40, 230, 80, 30);
label_of_password_box_of_LGB.setFont(new java.awt.Font("Consolas", 1, 14));
label_of_password_box_of_LGB.setForeground(new java.awt.Color(255, 0, 0));
inner_panel_of_LGB.add(label_of_password_box_of_LGB);
label_of_wrong_password_of_LGB = new JLabel("!*@_WrongPassword_@*!");
label_of_wrong_password_of_LGB.setBounds(130, 270, 170, 20);
label_of_wrong_password_of_LGB.setFont(new java.awt.Font("Consolas", 1, 14));
label_of_wrong_password_of_LGB.setForeground(new java.awt.Color(0, 0, 102));
inner_panel_of_LGB.add(label_of_wrong_password_of_LGB);
JButton Log_in_Button = new JButton("Log in");
Log_in_Button.setBounds(130, 320, 80, 30);
Log_in_Button.setBackground(new java.awt.Color(0, 0, 51));
Log_in_Button.setFont(new java.awt.Font("Consolas", 1, 12));
Log_in_Button.setForeground(new java.awt.Color(204, 255, 0));
inner_panel_of_LGB.add(Log_in_Button);
Log_in_Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
FileReader fr_LGB = new FileReader("name_password_tracker.txt");
BufferedReader br_LGB = new BufferedReader(fr_LGB);
String line_LGB;
ArrayList<String> recordList_LGB = new ArrayList<>();
while((line_LGB= br_LGB.readLine())!=null){
recordList_LGB.add(line_LGB);
}
fr_LGB.close();
br_LGB.close();
boolean both_matched = false;
boolean user_matched_pass_not_matched = false;
for(String records : recordList_LGB){
if(records.equals(username_box_of_LGB.getText()+"\t"+password_box_of_LGB.getText())){
both_matched=true;
break;
} else if(records.contains(username_box_of_LGB.getText())&&
(records.contains(password_box_of_LGB.getText()))==false){
user_matched_pass_not_matched = true;
break;
} else{
both_matched = false;
}
}
if(both_matched){
Forget_Password_Button.setEnabled(false);
label_of_wrong_password_of_LGB.setForeground(new java.awt.Color(0, 0, 102));
JFrame tem_LGB = new JFrame();
JOptionPane.showMessageDialog(tem_LGB,"Successfully Logged In...");
dispose();
}else if(user_matched_pass_not_matched){
label_of_wrong_password_of_LGB.setForeground(new java.awt.Color(255, 0, 0));
Forget_Password_Button.setEnabled(true);
} else if (both_matched == false) {
JFrame temporary_LGB = new JFrame();
JOptionPane.showMessageDialog(temporary_LGB,"Create an Account First!");
}
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
}
});
Forget_Password_Button = new JButton("Forget Password ?");
Forget_Password_Button.setBounds(30, 373, 270, 20);
Forget_Password_Button.setBackground(new java.awt.Color(0, 0, 51));
Forget_Password_Button.setFont(new java.awt.Font("Consolas", 1, 12));
Forget_Password_Button.setForeground(new java.awt.Color(255, 0, 0));
inner_panel_of_LGB.add(Forget_Password_Button);
Forget_Password_Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new FrameOfSignup();
}
});
JButton Dont_have_an_Account_Button = new JButton("Don't Have an Account ?");
Dont_have_an_Account_Button.setBounds(30, 400, 270, 22);
Dont_have_an_Account_Button.setBackground(new java.awt.Color(0, 0, 51));
Dont_have_an_Account_Button.setFont(new java.awt.Font("Consolas", 1, 12));
Dont_have_an_Account_Button.setForeground(new java.awt.Color(204, 255, 0));
inner_panel_of_LGB.add(Dont_have_an_Account_Button);
Dont_have_an_Account_Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new FrameOfSignup();
}
});
Forget_Password_Button.setEnabled(false);
setVisible(true);
}
}
Editor is loading...