Admin Login

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

package PovertyZero;

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class adminLogin implements ActionListener {

JFrame frame;
JLabel usernameIcon, passwordIcon;
JLabel shieldIcon, cart, possign, softwaresign;
JTextField username1;
JPasswordField password1;
JPanel panel;
JButton showbutton, loginButton,returnA;

adminUI ui = new adminUI();

public adminLogin() {
//pos.frame1.setVisible(false);

frame = new JFrame();


frame.setTitle("ADMIN");
frame.setSize(600, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(null);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.getContentPane().setBackground(new Color(128, 128, 128));

panel = new JPanel();


panel.setLayout(null);
panel.setBounds(290, 0, 300, 400);
panel.setBackground(new Color(192, 192, 192));

shieldIcon = new JLabel();


shieldIcon.setBounds(100, 30, 100, 100);
shieldIcon.setIcon(new
javax.swing.ImageIcon(getClass().getResource("/pic/shield.png")));
shieldIcon.setBackground(new Color(128, 128, 128));

usernameIcon = new JLabel();


usernameIcon.setBounds(20, 150, 25, 20);
usernameIcon.setIcon(new
javax.swing.ImageIcon(getClass().getResource("/pic/userimage.png")));
usernameIcon.setBackground(new Color(128, 128, 128));

username1 = new JTextField();


username1.setBounds(60, 140, 180, 30);
username1.setBackground(new Color(0, 255, 255));

passwordIcon = new JLabel();


passwordIcon.setBounds(20, 200, 25, 20);
passwordIcon.setIcon(new
javax.swing.ImageIcon(getClass().getResource("/pic/password.png")));
passwordIcon.setBackground(new Color(128, 128, 128));

password1 = new JPasswordField();


password1.setBounds(60, 190, 180, 30);
password1.setBackground(new Color(0, 255, 255));

showbutton = new JButton("SHOW");


showbutton.setBounds(60, 230, 90, 20);
showbutton.setBackground(new Color(0, 255, 255));
showbutton.setFocusable(false);
showbutton.addActionListener(this);

loginButton = new JButton("Log In");


loginButton.setBounds(150, 230, 90, 20);
loginButton.setBackground(new Color(0, 255, 255));
loginButton.setFocusable(false);
loginButton.addActionListener(this);

cart = new JLabel();


cart.setBounds(20, 80, 100, 100);
cart.setBackground(new Color(128, 128, 128));
cart.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pic/user
(1).png")));

possign = new JLabel();


possign.setText("ADMIN");
possign.setBounds(120, 30, 400, 200);
possign.setFont(new Font("MV Boli", Font.BOLD, 24));
possign.setForeground(new Color(0, 255, 255));

softwaresign = new JLabel();


softwaresign.setText("LOGIN");
softwaresign.setBounds(120, 50, 400, 200);
softwaresign.setFont(new Font("MV Boli", Font.BOLD, 24));
softwaresign.setForeground(new Color(0, 255, 255));

returnA = new JButton("Return");


returnA.setBounds(535,0,50,50);
returnA.setBackground(new Color(245, 221, 66));
returnA.setFocusable(false);
returnA.setBorder(null);

ui.returnA.addActionListener(this);

panel.add(softwaresign);
panel.add(possign);
panel.add(cart);
frame.add(returnA);
panel.add(loginButton);
frame.add(showbutton);
frame.add(password1);
frame.add(passwordIcon);
frame.add(username1);
frame.add(usernameIcon);
frame.add(shieldIcon);
frame.add(panel);
//ui.setVisible(false);
//frame.setVisible(true);
}

@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == loginButton) {
String username = "Admin";
String password = "Admin";

String inputUsername = username1.getText();

String inputPassword = password1.getText();

if (inputUsername.equals(username) && inputPassword.equals(password)) {


frame.setVisible(false);
ui.frame1.setVisible(true);

} else {
// The user has entered invalid credentials
JOptionPane.showMessageDialog(null, "Your username & password is
incorrect", "Error", JOptionPane.ERROR_MESSAGE);
}
}
if (e.getSource() == showbutton) {
char echoChar = password1.getEchoChar();
if (echoChar == 0) {
password1.setEchoChar('\u2022');
showbutton.setText("Show Password");
} else {
password1.setEchoChar((char) 0);
showbutton.setText("Hide Password");
}

}
if(e.getSource()==ui.returnA){
ui.frame1.setVisible(false);
frame.setVisible(true);
}

You might also like