Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LoginGUI extends JFrame implements ActionListener{
- public String userID;
- public int USERid;
- public LoginGUI(){
- try{
- SwingUtilities.invokeLater(new Runnable(){
- public void run(){
- createLog(300, 150);
- addCom();
- }
- });
- }
- catch(Exception e){
- System.err.println(e);
- }
- }
- public void createLog(int width, int height){
- this.setTitle("Login");
- this.setResizable(false);
- this.setSize(width, height);
- this.setLocationRelativeTo(null);
- this.setDefaultCloseOperation(3);
- this.setLayout(null);
- this.setVisible(true);
- this.getContentPane().setBackground(Color.PINK);
- }
- JLabel lblUsername, lblPassword;
- JButton btnLogin, btnSignUp;
- JTextField tfUsername;
- JPasswordField pfPassword;
- public void addCom(){
- lblUsername = new JLabel(" USERNAME|");
- lblPassword = new JLabel(" PASSWORD|");
- lblUsername.setBounds(10, 20, 100, 15);
- lblPassword.setBounds(10, 50, 100, 15);
- this.add(lblUsername);
- this.add(lblPassword);
- tfUsername = new JTextField();
- pfPassword = new JPasswordField();
- tfUsername.setBounds(87, 16, 150, 20);
- pfPassword.setBounds(87, 46, 150, 20);
- this.add(tfUsername);
- this.add(pfPassword);
- btnLogin = new JButton("LOGIN");
- btnSignUp = new JButton("SIGN UP");
- btnLogin.setBounds(180, 80, 100, 25);
- btnSignUp.setBounds(15, 80, 100, 25);
- btnLogin.addActionListener(this);
- btnSignUp.addActionListener(this);
- this.add(btnLogin);
- this.add(btnSignUp);
- }
- public void login(String username, String password){
- String sql = "SELECT tbl_account.accntName, tbl_account.accntPass, tbl_accounts.username, tbl_accounts.password FROM tbl_account, tbl_accounts";
- ResultSet rs = null;
- try{
- rs = mysql.executeQuery(stmt, sql);
- if(rs.next()){
- String managerUsername = rs.getString("accntName");
- String managerPassword = rs.getString("accntPass");
- String userUsername = rs.getString("username");
- String userPassword = rs.getString("password");
- if(username.equals(managerUsername)&&password.equals(managerPassword)){
- userID = rs.getString("accntPass");
- System.out.println("successful login as employee");
- JOptionPane.showMessageDialog(null, "Logged in as Employee");
- dispose();
- new Mprofile();
- }
- else if(username.equals(userUsername)&&password.equals(userPassword)){
- userID = rs.getString("username");
- System.out.println("login successful");
- JOptionPane.showMessageDialog(null, "Logged in as Customer");
- dispose();
- new Profile();
- }
- else{
- System.out.println("login unsuccessful");
- JOptionPane.showMessageDialog(null, "Login Failed.", "Access Denied.", JOptionPane.ERROR_MESSAGE);
- }
- }
- else{
- System.out.println("login unsuccessful");
- JOptionPane.showMessageDialog(null, "Login Failed.", "Access Denied.", JOptionPane.ERROR_MESSAGE);
- }
- }
- catch(Exception e){
- System.err.println(e);
- }
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- String command = e.getActionCommand();
- if(command.equals("LOGIN")){
- String username = this.tfUsername.getText();
- String password = this.pfPassword.getText();
- login(username, password);
- }
- else if(command.equals("SIGN UP")){
- dispose();
- new CreateAccnt();
- }
- }
- }
- public class Profile extends JFrame implements ActionListener{
- public String userID;
- public Profile(){
- try{
- javax.swing.SwingUtilities.invokeLater(new Runnable(){
- public void run(){
- createGUI(350, 300);
- addCompt();
- fillAccntData();
- }
- });
- }catch (Exception e){
- System.err.println(e);
- }
- }
- public void createGUI(int width, int height){
- this.setTitle("MY ACCOUNT");
- this.setResizable(false);
- this.setSize(width, height);
- this.setLocationRelativeTo(null);
- this.setDefaultCloseOperation(3);
- this.setLayout(null);
- this.setVisible(true);
- this.getContentPane().setBackground(Color.DARK_GRAY);
- }
- JLabel Uname, ID, cont, num, email, opt;
- JButton delAccnt, UpAccnt, MCart, back, Log;
- JTextField username, id, Cnum, em;
- public void addCompt(){
- Log = new JButton("Logout");
- Log.setBounds(175, 210, 150, 25);
- Log.addActionListener(this);
- Log.setForeground(Color.WHITE);
- Log.setBackground(Color.BLACK);
- Log.setCursor(new Cursor(Cursor.HAND_CURSOR));
- Log.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- new LoginGUI();
- dispose();
- }
- });
- this.add(Log);
- Uname = new JLabel ("Username|");
- Uname.setBounds(12, 20, 100, 20);
- this.add(Uname);
- ID = new JLabel("User ID|");
- ID.setBounds(12, 50, 100, 20);
- this.add(ID);
- cont = new JLabel("Contact ");
- cont.setBounds(12, 80, 100, 20);
- this.add(cont);
- num = new JLabel("Number| ");
- num.setBounds(12, 93, 100, 20);
- this.add(num);
- email = new JLabel("Email: ");
- email.setBounds(12, 120, 100, 20);
- this.add(email);
- opt = new JLabel("OPTIONS: ");
- opt.setBounds(135, 150, 100, 20);
- this.add(opt);
- //
- delAccnt = new JButton ("Delete Account");
- delAccnt.setBounds(12, 180, 150, 25);
- this.add(delAccnt);
- UpAccnt = new JButton ("Update Account");
- UpAccnt.setBounds(12, 210, 150, 25);
- this.add(UpAccnt);
- MCart = new JButton ("My Cart");
- MCart.setBounds(175, 180, 150, 25);
- this.add(MCart);
- back = new JButton ("HOME");
- back.setBounds(90, 240, 150, 25);
- this.add(back);
- //
- username = new JTextField();
- username.setBounds(100, 20, 150, 20);
- username.setEditable(false);
- this.add(username);
- id = new JTextField();
- id.setBounds(100, 50, 150, 20);
- id.setEditable(false);
- this.add(id);
- Cnum = new JTextField();
- Cnum.setBounds(100, 85, 150, 20);
- Cnum.setEditable(false);
- this.add(Cnum);
- em = new JTextField();
- em.setBounds(100, 120, 150, 20);
- em.setEditable(false);
- this.add(em);
- }
- public void fillAccntData(){
- new LoginGUI().userID.getClass().equals(userID);
- String sql = "SELECT * FROM tbl_accounts WHERE username = '" +userID;
- ResultSet rs = null;
- try{
- rs = mysql.executeQuery(stmt, sql);
- while(rs.next()){
- this.id.setText(rs.getInt("id")+"");
- this.username.setText(rs.getString("username")+"");
- this.Cnum.setText(rs.getString("contact_number")+"");
- this.em.setText(rs.getString("email")+"");
- }
- }
- catch(Exception e){
- System.err.println(e);
- }
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- String cmd = e.getActionCommand();
- if(cmd.equals("Delete Account")){
- int dButt = JOptionPane.YES_NO_OPTION;
- JOptionPane.showConfirmDialog(null, "ARE YOU SURE?", "WARNING!", dButt);
- if(dButt == JOptionPane.YES_OPTION){
- try {
- String sql = "DELETE FROM tbl_accounts WHERE ID = ";
- mysql.executeUpdate(stmt, sql);
- JOptionPane.showMessageDialog(null, "ACCOUNT HAS BEEN SUCCESSFULLY REMOVED!");
- } catch (Exception ex) {
- System.err.println(ex);
- }
- dispose();
- new LoginGUI();
- } else if (dButt == JOptionPane.NO_OPTION){
- new Profile();
- }
- } else if (cmd.equals("Update Account")){
- dispose();
- new UpdateAccountGUI();
- } else if(cmd.equals("My Cart")){
- } else if(cmd.equals("HOME")){
- dispose();
- new Home();
- }
- }
- }
Add Comment
Please, Sign In to add comment