Skip to content
Snippets Groups Projects
Commit ec1bd200 authored by mkandel2's avatar mkandel2
Browse files

User Login form

parent ebe06ccd
Branches UserLogin
No related tags found
No related merge requests found
......@@ -3,12 +3,15 @@
*/
package brickbreaker;
public class App {
public String getGreeting() {
return "Hello World!";
}
import javax.swing.JFrame;
public class App {
public static void main(String[] args) {
System.out.println(new App().getGreeting());
LoginFrame frame=new LoginFrame();
frame.setTitle("Register || Brick Breaker");
frame.setVisible(true);
frame.setBounds(10,10,370,600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
}
}
/*
* 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
*/
public class GamePanel {
}
/*
* 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()");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment