0% found this document useful (0 votes)
98 views6 pages

Practical 10 PDF

The document describes a program to create two login forms: 1) A login form for a social networking site with username and password fields and a login button. It checks the credentials and displays a toast message. 2) A login form for a student registration system with additional fields for enrollment number, CRN, class, roll number, and department. It checks the credentials and additional details and displays an appropriate toast message.

Uploaded by

Ajinkya Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views6 pages

Practical 10 PDF

The document describes a program to create two login forms: 1) A login form for a social networking site with username and password fields and a login button. It checks the credentials and displays a toast message. 2) A login form for a student registration system with additional fields for enrollment number, CRN, class, roll number, and department. It checks the credentials and additional details and displays an appropriate toast message.

Uploaded by

Ajinkya Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Practical No. 10 : Develop a program to implement login window using above UI controls.

Name: Ajinkya P. Patil Class: TYCM-II Roll No.: 39

1. Write a Program to create a login form for a social networking site.

activity_main.xml Code:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity">

<TextView
android:id="@+id/textViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:text="Login Form"
android:layout_gravity="center"/>

<EditText
android:id="@+id/editTextUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:inputType="text"
android:padding="8dp"
android:layout_marginTop="16dp"/>

<EditText
android:id="@+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:padding="8dp"
android:layout_marginTop="16dp"/>

<Button
android:id="@+id/buttonLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:textSize="18sp"
android:layout_marginTop="16dp"/>

</LinearLayout>

MainActivity.java Code:
package com.example.pr_10_social_network;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

EditText editTextUsername = findViewById(R.id.editTextUsername);


EditText editTextPassword = findViewById(R.id.editTextPassword);
Button buttonLogin = findViewById(R.id.buttonLogin);

buttonLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username = editTextUsername.getText().toString();
String password = editTextPassword.getText().toString();

// Perform authentication
if (username.equals("Ajinkya Patil") &&
password.equals("Social Password")) {
Toast.makeText(getApplicationContext(), "Login
successful", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "Invalid
username or password", Toast.LENGTH_SHORT).show();
}

}
});
}
}
Output:

2. Write a program to create login form for student registration system.

activity_main.xml code :

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity">

<TextView
android:id="@+id/textViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Student Registration System"
android:textSize="24sp" />
<EditText
android:id="@+id/editTextUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:inputType="text"
android:padding="8dp"
android:layout_marginTop="16dp"/>

<EditText

android:id="@+id/Enroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enrollment No.: "
android:inputType="text"
android:padding="8dp"
android:layout_marginTop="16dp"/>

<EditText

android:id="@+id/CRN"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="CRN No.: "
android:inputType="text"
android:padding="8dp"
android:layout_marginTop="16dp"/>

<EditText
android:id="@+id/cla"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="class : "
android:inputType="text"
android:padding="8dp"
android:layout_marginTop="16dp"/>

<EditText
android:id="@+id/Roll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Roll No : "
android:inputType="text"
android:padding="8dp"
android:layout_marginTop="16dp"/>

<EditText
android:id="@+id/dept"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Department: "
android:inputType="text"
android:padding="8dp"
android:layout_marginTop="16dp"/>

<EditText
android:id="@+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:padding="8dp"
android:layout_marginTop="16dp"/>

<Button
android:id="@+id/buttonLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:textSize="18sp"
android:layout_marginTop="16dp"/>

</LinearLayout>

MainActivity.java code:

package com.example.pr_10_student_registration_system;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

EditText usernameEditText = findViewById(R.id.editTextUsername);


EditText passwordEditText = findViewById(R.id.editTextPassword);
EditText Enroll = findViewById(R.id.Enroll);
EditText CRN = findViewById(R.id.CRN);
EditText cla = findViewById(R.id.cla);
EditText Roll = findViewById(R.id.Roll);
EditText dept = findViewById(R.id.dept);
Button loginButton = findViewById(R.id.buttonLogin);

loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

String username = usernameEditText.getText().toString();


String password = passwordEditText.getText().toString();

if (username.equals("Ajinkya Patil") &&


password.equals("Student Password")) {
if (Enroll.equals("2000780314") &&
CRN.equals("S0220031055") && cla.equals("TYCM-II") && Roll.equals("39") &&
dept.equals("CM")){

Toast.makeText(getApplicationContext(), "Username
and Password and student Details are correct !",
Toast.LENGTH_SHORT).show();

}
else {

Toast.makeText(getApplicationContext(), "Student
Details are not correct ", Toast.LENGTH_SHORT).show();
}

} else {
Toast.makeText(getApplicationContext(), "Invalid
username or password", Toast.LENGTH_SHORT).show();
}
}

});

}
}

Output:

You might also like