Here I give full source code in Java and XMl, Sample output with mobile application in .apk format.
EX.NO 1 Develop an application that uses GUI components, Font and Colours
Aim:
To develop a Simple Android Application that uses GUI components, Font and Colors.
Procedure:
Creating a New project:
- First open the Android studio tool.
- Then click on File -> New -> New project.
- Then select a Project Template
- Then configure your project, Select the language and Minimum SDK, I recommend use Oreo or Pie Android version.
- Finally click Finish.
- Successfully create your project, Its Java file.
- Its designing part click on split button , Open the XML file.
Program:
XML code:
activity_main.xml:
<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout android:layout_height=”match_parent” android:layout_width=”match_parent”
android:orientation=”vertical”
xmlns:android=”http://schemas.android.com/apk/res/android”>
<TextView
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:id=”@+id/tv1″
android:text=”Hello World”
android:gravity=”center”
android:textStyle=”bold”
android:textSize=”25sp”
android:layout_margin=”30dp”
/>
<Button
android:id=”@+id/button1″
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_margin=”20dp”
android:gravity=”center”
android:text=”Change font size”
android:textSize=”25sp” android:backgroundTint=”@color/black”/>
<Button
android:id=”@+id/button2″
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_margin=”20dp”
android:gravity=”center”
android:text=”Change color”
android:textSize=”25sp”
android:backgroundTint=”@color/black”
/>
<TextView
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”Mobile Application Development Laboratory”
android:textColor=”#0000FF”
android:gravity=”center”
android:textStyle=”bold”
android:textSize=”25sp”
android:layout_margin=”30dp”
/>
</LinearLayout>
- Now click on Design and your application will look as given below.
- So now the designing part is completed.
Java Coding for the Android Application:
- Click on app -> java -> com.example.expriment1 -> MainActivity.java
Java code:
package com.example.expriment1;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
int ch=1;
float font=30;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView t1 = (TextView) findViewById(R.id.tv1);
Button b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
t1.setTextSize(font);
font = font+5;
if (font==50)
{
font=30;
}
}
});
Button b2 = (Button) findViewById(R.id.button2);
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (ch) {
case 1:
t1.setTextColor(Color.RED);
break;
case 2:
t1.setTextColor(Color.GREEN);
break;
case 3:
t1.setTextColor(Color.BLUE);
break;
case 4:
t1.setTextColor(Color.CYAN);
break;
case 5:
t1.setTextColor(Color.YELLOW);
break;
case 6:
t1.setTextColor(Color.MAGENTA);
break;
}
ch++;
if (ch == 7) {
ch = 1;
}
}
});
}
}
- So now the Coding part is also completed.
- Now run the application to see the output.
Output:
Result:
Thus a Simple Android Application that uses GUI components, Font and Colors is developed and executed successfully.
Here I was attach my Mobile Application in .apk format.
Click on blow link: (Download the mobile app)
https://drive.google.com/file/d/1IOk12PnF2FlrYtw_aYYnEfFjW_XLEPIe/view?usp=sharing
EX.NO 2.a. Develop an application that uses Table Layout manager and Event Listener
Aim:
To develop an application that uses Table Layout manager and Event Listener
Procedure:
Create an XML file with table layout.
Give separate ID for each and every fields of the XML file.
Create a Java file with event listener for XML file.
Set an actionListener and eventListener commands to specify and perform the operations.
Using the OnClickListener create a method for the button clicking events used in Java
PROGRAM:
XML CODING:
File Name: activity_main.xml
<?xml version=”1.0″ encoding=”utf-8″?>
<TableLayout android:layout_width=”match_parent” android:layout_height=”match_parent”
xmlns:android=”http://schemas.android.com/apk/res/android”
android:stretchColumns=”*”>
<TableRow>
<TextView android:layout_width=”match_parent” android:text=”Persentage Calculator”
android:layout_span=”2″
android:gravity=”center” android:textStyle=”bold” android:textSize=”20sp”/>
</TableRow>
<TableRow>
<TextView android:text=”Tamil”/>
<EditText android:width=”220dp” android:id=”@+id/a1″/>
</TableRow>
<TableRow>
<TextView android:text=”English”/>
<EditText android:width=”220dp” android:id=”@+id/a2″/>
</TableRow>
<TableRow>
<TextView android:text=”Maths”/>
<EditText android:width=”220dp” android:id=”@+id/a3″/>
</TableRow>
<TableRow>
<TextView android:text=”Science”/>
<EditText android:width=”220dp” android:id=”@+id/a4″/>
</TableRow>
<TableRow>
<TextView android:text=”Social”/>
<EditText android:width=”220dp” android:id=”@+id/a5″/>
</TableRow>
<TableRow>
<TextView android:text=”Total”/>
<EditText android:width=”220dp” android:id=”@+id/a6″/>
</TableRow>
<TableRow>
<TextView android:text=”Average”/>
<EditText android:width=”220dp” android:id=”@+id/a7″/>
</TableRow>
<TableRow>
<TextView android:text=”Results”/>
<EditText android:width=”220dp” android:id=”@+id/a8″/>
</TableRow>
<TableRow>
<Button android:text=”Submit” android:onClick=”calculate”/>
</TableRow>
</TableLayout>
JAVA CODING:
File Name: MainActivity.java
package com.example.expriment2;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
EditText a1,a2,a3,a4,a5,a6,a7,a8;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
a1=findViewById(R.id.a1);
a2=findViewById(R.id.a2);
a3=findViewById(R.id.a3);
a4=findViewById(R.id.a4);
a5=findViewById(R.id.a5);
a6=findViewById(R.id.a6);
a7=findViewById(R.id.a7);
a8=findViewById(R.id.a8);
}
public void calculate(View v)
{
int a=Integer.parseInt(a1.getText().toString());
int b=Integer.parseInt(a2.getText().toString());
int c=Integer.parseInt(a3.getText().toString());
int d=Integer.parseInt(a4.getText().toString());
int e=Integer.parseInt(a5.getText().toString());
int tot=a+b+c+d+e;
int avg=tot/5;
a6.setText(String.valueOf(tot));
a7.setText(String.valueOf(avg));
a8.setText(a>40&& b>40&&c>40&&d>40 &&e>40?”Pass”:”Fail”);
}
}
OUTPUT:
Result:
Thus a Simple Android Application that uses table layout manager and event listener developed and executed successfully.
Here I was attach my Mobile Application in .apk format.
Click on blow link: (Download the mobile app)
https://drive.google.com/file/d/1R5mWxvXD8n8ir5slOal8pzN-lC3U54p5/view?usp=sharing
EX.NO 2.b Develop an application that uses Relative Layout manager and Event Listener
Aim:
To develop an application that uses Relative Layout manager and Event Listener
Procedure:
Create an XML file with relative layout.
Give separate ID for each and every fields of the XML file.
Create a Java file with event listener for XML file.
Set an actionListener and eventListener commands to specify and perform the operations.
Using the OnClickListener create a method for the button clicking events used in Java
PROGRAM:
XML CODING:
File Name: activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <TextView android:id="@+id/tv1" android:layout_width="match_parent" android:layout_height="wrap_content" android:textAlignment="center" android:text="Persentage Calculator" /> <TextView android:id="@+id/tv2" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_below="@+id/tv1" android:text="Tamil" /> <EditText android:id="@+id/et1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/tv1" android:layout_toRightOf="@+id/tv2" /> <TextView android:id="@+id/tv3" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/et1" /> <TextView android:id="@+id/tv4" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_below="@+id/tv3" android:text="English" /> <EditText android:id="@+id/et2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/tv3" android:layout_toRightOf="@+id/tv4" /> <TextView android:id="@+id/tv5" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/et2" /> <TextView android:id="@+id/tv6" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_below="@+id/tv5" android:text="Maths" /> <EditText android:id="@+id/et3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/tv5" android:layout_toRightOf="@+id/tv6" /> <TextView android:id="@+id/tv7" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/et3" /> <TextView android:id="@+id/tv8" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_below="@+id/tv7" android:text="Science" /> <EditText android:id="@+id/et4" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/tv7" android:layout_toRightOf="@+id/tv8" /> <TextView android:id="@+id/tv9" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/et4" /> <TextView android:id="@+id/tv10" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_below="@+id/tv9" android:text="Social" /> <EditText android:id="@+id/et5" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/tv9" android:layout_toRightOf="@+id/tv10" /> <TextView android:id="@+id/tv11" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/et5" /> <TextView android:id="@+id/tv12" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_below="@+id/tv11" android:text="Total" /> <EditText android:id="@+id/et6" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/tv11" android:layout_toRightOf="@+id/tv12" /> <TextView android:id="@+id/tv13" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/et6" /> <TextView android:id="@+id/tv14" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_below="@+id/tv13" android:text="Result" /> <EditText android:id="@+id/et7" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/tv13" android:layout_toRightOf="@+id/tv14" /> <TextView android:id="@+id/tv15" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/et7" /> <TextView android:id="@+id/tv16" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_below="@+id/tv15" android:text="Average" /> <EditText android:id="@+id/et8" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/tv15" android:layout_toRightOf="@+id/tv16" /> <TextView android:id="@+id/tv17" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/et8" /> <Button android:id="@+id/tv18" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_below="@+id/tv17" android:text="Submit" android:onClick="calculate"/> </RelativeLayout>
JAVA CODING:
File Name: MainActivity.java
package com.example.expriment2b;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
EditText a1,a2,a3,a4,a5,a6,a7,a8;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
a1=findViewById(R.id.et1);
a2=findViewById(R.id.et2);
a3=findViewById(R.id.et3);
a4=findViewById(R.id.et4);
a5=findViewById(R.id.et5);
a6=findViewById(R.id.et6);
a7=findViewById(R.id.et7);
a8=findViewById(R.id.et8);
}
public void calculate(View v)
{
int a=Integer.parseInt(a1.getText().toString());
int b=Integer.parseInt(a2.getText().toString());
int c=Integer.parseInt(a3.getText().toString());
int d=Integer.parseInt(a4.getText().toString());
int e=Integer.parseInt(a5.getText().toString());
int tot=a+b+c+d+e;
int avg=tot/5;
a6.setText(String.valueOf(tot));
a7.setText(String.valueOf(avg));
a8.setText(a>40&& b>40&&c>40&&d>40 &&e>40?"Pass":"Fail");
}
}
OUTPUT:
Result:
Thus a Simple Android Application that uses relative layout manager and event listener developed and executed successfully.
Here I was attach my Mobile Application in .apk format.
Click on blow link: (Download the mobile app run in your mobile)
https://drive.google.com/file/d/1R5mWxvXD8n8ir5slOal8pzN-lC3U54p5/view?usp=sharing
EX.NO 3 Write an application that draws basic graphical primitives on the screen.
Aim:
To develop a Simple Android Application that draws basic Graphical Primitives on the screen.
Procedure:
Open android studio and create new project
Select our project in the project explorer
Go to res folder and select layout Double click the main xml file
Type the code for main.xml or drag and drop various components used in our program
Drag and drop relative layout and change its properties
Drag and drop image view and change its properties according to our programs
Screen layout can be viewed by clicking graphics layout tab
Include necessary files
Override OnCreate() function
Create Image view and initialize its using id of some components used in the xml program
Save the program
Run the program
Output can be viewed in the android emulator
PROGRAM:
XML CODING:
File Name: activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/ImageView"/>
</RelativeLayout>
JAVA CODING:
File Name: MainActivity.java
package com.example.experiment3;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Creating a Bitmap
Bitmap bg = Bitmap.createBitmap(720, 1280,
Bitmap.Config.ARGB_8888);
//Setting the Bitmap as background for the ImageView
ImageView i = (ImageView) findViewById(R.id.ImageView);
i.setBackgroundDrawable(new BitmapDrawable(bg));
//Creating the Canvas Object
Canvas canvas = new Canvas(bg);
//Creating the Paint Object and set its color & TextSize
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setTextSize(50);
//To draw a Rectangle
canvas.drawText("Rectangle", 420, 150, paint);
canvas.drawRect(400, 200, 650, 700, paint);
//To draw a Circle
canvas.drawText("Circle", 120, 150, paint);
canvas.drawCircle(200, 350, 150, paint);
//To draw a Square
canvas.drawText("Square", 120, 800, paint);
canvas.drawRect(50, 850, 350, 1150, paint);
//To draw a Line
canvas.drawText("Line", 480, 800, paint);
canvas.drawLine(520, 850, 520, 1150, paint);
}
}
Output:
Result:
Thus a Simple Android Application that draws basic Graphical Primitives on the screen is developed and executed successfully.
Here I was attach my Mobile Application in .apk format.
Click on blow link: (Download the mobile app run in your mobile)
https://drive.google.com/file/d/1KIp-q2YrMIUR3WLLBVQvIDpxof-Aw009/view?usp=sharing
Any quires leave a comment , I will Try to answer soon.