Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package accountmanager;
- /**
- *
- * @author Rengi
- */
- import java.awt.Color;
- import java.sql.*;
- import javax.swing.*;
- public class LogInScreen extends javax.swing.JFrame {
- Connection conn = null;
- ResultSet rs = null;
- PreparedStatement pst = null;
- /**
- * Creates new form MainScreen
- */
- public LogInScreen() {
- initComponents();
- lblError.setVisible(false);
- }
- /**
- * 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() {
- jPanel1 = new javax.swing.JPanel();
- tbxUsername = new javax.swing.JTextField();
- lbxPass = new javax.swing.JLabel();
- lblUsername = new javax.swing.JLabel();
- btnSignIn = new javax.swing.JButton();
- jButton1 = new javax.swing.JButton();
- tbxPassword = new javax.swing.JPasswordField();
- lblError = new javax.swing.JLabel();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setTitle("Profile Manager Log-In");
- addKeyListener(new java.awt.event.KeyAdapter() {
- public void keyPressed(java.awt.event.KeyEvent evt) {
- formKeyPressed(evt);
- }
- });
- jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Login/Register"));
- lbxPass.setText("Password:");
- lblUsername.setText("Username:");
- btnSignIn.setIcon(new javax.swing.ImageIcon("C:\\Users\\Rengi\\Documents\\NetBeansProjects\\AccountManager\\login.png")); // NOI18N
- btnSignIn.setText("Sign In");
- btnSignIn.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnSignInActionPerformed(evt);
- }
- });
- jButton1.setIcon(new javax.swing.ImageIcon("C:\\Users\\Rengi\\Documents\\NetBeansProjects\\AccountManager\\register.png")); // NOI18N
- jButton1.setText("Register");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(lblUsername)
- .addComponent(lbxPass))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(tbxPassword)
- .addComponent(tbxUsername)))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jButton1)
- .addGap(104, 104, 104)
- .addComponent(btnSignIn)))
- .addContainerGap())
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(lblUsername)
- .addComponent(tbxUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(lbxPass)
- .addComponent(tbxPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1)
- .addComponent(btnSignIn))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- lblError.setForeground(new java.awt.Color(255, 102, 102));
- lblError.setText(" The username or password is incorrect, please try again");
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(17, 17, 17)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(lblError, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addContainerGap(16, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(lblError)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- pack();
- setLocationRelativeTo(null);
- }// </editor-fold>
- Accounts ac = new Accounts();
- public void getOwnerId(){
- try{
- Accounts.ownerid = rs.getString("userid");
- rs = pst.executeQuery();
- }catch(Exception e){
- System.out.println(e);
- }
- }
- private void btnSignInActionPerformed(java.awt.event.ActionEvent evt) {
- conn = MySqlConnect.ConnectDB();
- String Sql = "SELECT * FROM login where username=? and password=?";
- try{
- pst = conn.prepareStatement(Sql);
- pst.setString(1, tbxUsername.getText());
- pst.setString(2, tbxPassword.getText());
- rs = pst.executeQuery();
- if(rs.next()){
- getOwnerId();
- setVisible(false);
- Accounts ac = new Accounts();
- ac.setVisible(true);
- ac.send2Console(new Color(145, 223, 255),"userid: " + Accounts.ownerid + " has logged in.");
- }else{
- lblError.setVisible(true);
- }
- }
- catch(Exception e){
- JOptionPane.showMessageDialog(null, e);
- }
- }
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- setVisible(false);
- Register rg = new Register();
- rg.setVisible(true);
- }
- private void formKeyPressed(java.awt.event.KeyEvent evt) {
- // TODO add your handling code here:
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Windows".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(LogInScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(LogInScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(LogInScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(LogInScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new LogInScreen().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton btnSignIn;
- private javax.swing.JButton jButton1;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JLabel lblError;
- private javax.swing.JLabel lblUsername;
- private javax.swing.JLabel lbxPass;
- private javax.swing.JPasswordField tbxPassword;
- private javax.swing.JTextField tbxUsername;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement