/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package inventorysystem.gui;
import inventorysystem.data.Employee;
import inventorysystem.data.Login;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import inventorysystem.InventorySystem;
import interfaces.Switchable;
import java.util.logging.Logger;
/**
*
* @author Epic
*/
public class login
extends javax.
swing.
JPanel implements Switchable
{
private static boolean loggedIn = false;
private static Employee currentEmployee = null;
/**
* Creates new form login
*/
public login() {
initComponents();
this.setName("Login Panel");
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1
= new javax.
swing.
JLabel();
jLabel2
= new javax.
swing.
JLabel();
btnLogin
= new javax.
swing.
JButton();
jLabel3
= new javax.
swing.
JLabel();
lblWrong
= new javax.
swing.
JLabel();
jLabel1.
setFont(new java.
awt.
Font("Dialog",
0,
14)); // NOI18N
jLabel1.setText("Username:");
jLabel2.
setFont(new java.
awt.
Font("Dialog",
0,
14)); // NOI18N
jLabel2.setText("Password:");
btnLogin.
setFont(new java.
awt.
Font("Dialog",
1,
12)); // NOI18N
btnLogin.setText("Login");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
btnLoginActionPerformed(evt);
}
});
jLabel3.
setFont(new java.
awt.
Font("Dialog",
1,
18)); // NOI18N
jLabel3.setText("Inventory System for Group 1");
lblWrong.
setFont(new java.
awt.
Font("Dialog",
0,
14)); // NOI18N
lblWrong.
setForeground(new java.
awt.
Color(255,
0,
0));
lblWrong.setText("Wrong user credentials");
lblWrong.setVisible(false);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(30, 30, 30)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.
addComponent(jLabel3, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
376,
Short.
MAX_VALUE)
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.
addComponent(lblWrong, javax.
swing.
GroupLayout.
DEFAULT_SIZE, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
Short.
MAX_VALUE)
.
addComponent(btnLogin, javax.
swing.
GroupLayout.
DEFAULT_SIZE, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
Short.
MAX_VALUE)
.addComponent(txtUsername, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtPassword, javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING))
.
addGap(0,
0,
Short.
MAX_VALUE)))
.addGap(22, 22, 22))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(35, 35, 35)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel2)
.addGap(2, 2, 2)
.addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.
addPreferredGap(javax.
swing.
LayoutStyle.
ComponentPlacement.
RELATED,
18,
Short.
MAX_VALUE)
.addComponent(lblWrong)
.addGap(18, 18, 18)
.addComponent(btnLogin)
.addGap(32, 32, 32))
);
}// </editor-fold>
private void btnLoginActionPerformed
(java.
awt.
event.
ActionEvent evt
) {
// TODO add your handling code here:
Login l = new Login();
this.currentEmployee = l.isUser(txtUsername.getText(), txtPassword.getText());
if(null != this.currentEmployee){
lblWrong.setVisible(false);
JOptionPane.
showMessageDialog(null,
"Welcome ".
concat(this.
currentEmployee.
getUsername()));
loggedIn = true;
//Goto new panel on the block
this.OnPanelSwitched(new Dashboard());
}else{
lblWrong.setVisible(true);
}
}
// <editor-fold defaultstate="collapsed" desc="Initialize variables">
// Variables declaration - do not modify
private javax.
swing.
JButton btnLogin
;
private javax.
swing.
JLabel jLabel1
;
private javax.
swing.
JLabel jLabel2
;
private javax.
swing.
JLabel jLabel3
;
private javax.
swing.
JLabel lblWrong
;
// End of variables declaration
//</editor-fold>
@Override
public void OnPanelSwitched
(JPanel panelToSwitch
) {
InventorySystem.switchPanel(panelToSwitch,loggedIn);
System.
out.
println("I have been called oh bro to change the panel "+panelToSwitch.
getName());
}
public static boolean isLoggedIn() {
return loggedIn;
}
public static Employee getCurrentEmployee() {
return currentEmployee;
}
private static final Logger LOG = Logger.getLogger(login.class.getName());
}