/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package brickbreaker;

/**
 *
 * @author Suman
 */
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
public class LoginFrame extends JFrame implements ActionListener {
 
    Container container=getContentPane();
    JLabel userLabel=new JLabel("USERNAME");
    JLabel passwordLabel=new JLabel("PASSWORD");
    JTextField userNameTextField=new JTextField();
    JPasswordField passwordField=new JPasswordField();
    JButton loginButton=new JButton("LOGIN");
    JButton registerButton=new JButton("REGISTER");
 
 
    LoginFrame()
    {
       //Calling methods inside constructor.
        setLayoutManager();
        setLocationAndSize();
        addComponentsToContainer();
        addActionListeners();
    }
   public void setLayoutManager()
   {
       container.setLayout(null);
   }
   public void setLocationAndSize()
   {
       //Setting location and Size of each components using setBounds() method.
       userLabel.setBounds(50,150,100,30);
       passwordLabel.setBounds(50,220,100,30);
       userNameTextField.setBounds(150,150,150,30);
       passwordField.setBounds(150,220,150,30);
       loginButton.setBounds(50,300,100,30);
       registerButton.setBounds(200,300,100,30);
 
 
   }
   public void addComponentsToContainer()
   {
      //Adding each components to the Container
       container.add(userLabel);
       container.add(passwordLabel);
       container.add(userNameTextField);
       container.add(passwordField);
       container.add(loginButton);
       container.add(registerButton);
   }
   
   public void addActionListeners() {
       loginButton.addActionListener(this);
       registerButton.addActionListener(this);
   }
 
 
    @Override
    public void actionPerformed(ActionEvent e) {
        String actionCommand = e.getActionCommand();
        switch(actionCommand) {
            case "LOGIN":
                handleLogin();
                break;
            
            case "REGISTER":
                handleRegister();
        }
    }
    
    private void handleLogin() {
        String password = new String(passwordField.getPassword());
        String userName = userNameTextField.getText();
        System.out.println("user Nmae: " + userName + " password: " + password);
    }
    
    private void handleRegister() {
        System.out.println("brickbreaker.LoginFrame.handleRegister()");
    }
}