S. NO DATE TITLE OF THE PROGRAM PAGE.
NO
1 09/12/2024 PERFECT NUMBER 1
2 12/12/2024 PALINDROME NUMBER 3
3 12/12/2024 NUMBER PATTERN 4
4 16/12/2024 BIGGEST OF THREE NUMBERS USING COMMAND LINE 6
ARGUMENT
5 17/12/2024 SORTING NUMBERS 7
6 20/12/2024 MATRIX ADDITION 9
7 23/12/2024 MATRIX MULTIPLICATION 12
8 24/12/2024 PRINTING ZERO AT THE LAST OF AN ARRAY 15
9 28/12/2024 STUDENT DETAILS USING CLASS 17
10 31/12/2024 AREA CALCULATION USING METHOD OVERLOADING 19
11 02/01/2025 VOLUME CALCULATION USING CONSTRUCTOR 21
OVERLOADING
12 06/01/2025 OBJECT AS PARAMETER 23
13 06/01/2025 STACK CLASS
14 09/01/2025 EMPLOYEE SALARY DETAILS USING SINGLE 24
INHERITANCE
15 09/01/2025 STUDENT DETAILS USING MULTILEVEL INHERITANCE 26
16 20/01/2025 METHOD OVERRIDING 28
17 20/01/2025 DYNAMIC METHOD DISPATCH 30
18 24/01/2025 ARITHMETIC OPERATIONS USING PACKAGE 32
19 31/01/2025 AREA CALCULATION USING INTERFACE 36
20 10/02/2025 FACTORIAL OF A NUMBER USING RECURSION 38
21 10/02/2025 BUILT-IN EXCEPTION 40
22 12/02/2025 USER DEFINED EXCEPTION 41
23 15/02/2025 MULTITHREADED PROGRAMMING USING RUNNABLE 43
INTERFACE
24 15/02/205 STRING MANIPULATION 45
25 18/02/2025 FACE USING GRAPHICS CLASS
26 19/02/2025 ANIMATION 47
27 24/02/2025 FONT AND COLOR CLASS 50
28 27/02/2025 DRAWING SHAPES USING GRAPHICAL METHODS 57
29 03/03/2025 AWT BASIC CONTROL 53
30 12/03/2025 GRID LAYOUT 56
Perfect Number
Ex No.1
Aim:
To write a java program to display whether the given number is perfect or not.
Code:
import [Link].*;
class Perfect
{
public static void main(String args[])
{
int i,n,sum=0;
Scanner sc=new Scanner([Link]);
[Link]("Enter the number");
n=[Link]();
for(i=1;i<n;i++)
{
if(n%i==0)
{
sum=sum+i;
}
}
if(sum==n)
[Link](n+" is a perfect number");
else
[Link](n+" is not a perfect number");
}
1
Output:
2
Palindrome Number
Ex No.2
Aim:
To write a java program to display whether the given number is palindrome or not.
Code:
import [Link].*;
class Palindrome
{
public static void main(String args[])
{
int n,m,r,sum=0;
Scanner sc=new Scanner([Link]);
[Link]("Enter a number:");
n=[Link]();
m=n;
while(n!=0)
{
r=n%10;
sum=sum*10+r;
n=n/10;
}
if(m==sum)
[Link](sum+ " is a palindrome");
else
[Link](sum+ " is not a palindrome");
}
}
Output:
3
Number Pattern
Ex No.3
Aim:
To write a java program to print forward and backward pattern triangle.
Code:
import [Link].*;
class Pattern
{
public static void main(String args[])
{
int i,j,k,n;
Scanner sc=new Scanner([Link]);
[Link]("Enter a range:");
n=[Link]();
[Link]("The pattern for forward triangle is:");
for(i=0;i<n;i++)
{
k=1;
for(j=0;j<=i;j++)
{
[Link](k+" ");
k++;
}
[Link]();
}
[Link]("The pattern for backward triangle:");
for(i=0;i<n;i++)
{
k=1;
for(j=i+1;j<=n;j++)
{
[Link](k+" ");
k++;
}
[Link]();
}
4
}
}
Output:
5
Biggest Of Three Numbers Using Command Line Arguments
Ex No.4
Aim:
To write a java program to find biggest of three numbers using command line arguments.
Code:
class Biggest
{
public static void main(String args[])
{
int a=[Link](args[0]);
int b=[Link](args[1]);
int c=[Link](args[2]);
if((a>b)&&(a>c))
[Link](a+" is biggest");
else if(b>c)
[Link](b+" is biggest");
else
[Link](c+" is biggest");
}
}
Output:
6
Sorting Numbers
Ex No.5
Aim:
To write a java program to sort numbers in an given array.
Code:
import [Link].*;
class Sorting
{
public static void main(String args[])
{
int n,i,j,t;
Scanner sc=new Scanner([Link]);
[Link]("Enter the range:");
n=[Link]();
int a[]=new int[n];
[Link]("Enter the values:");
for(i=0;i<n;i++)
{
a[i]=[Link]();
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(a[i]<a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
[Link]("Sorted numbers are");
for(i=0;i<n;i++)
[Link](a[i]);
}
7
}
Output:
8
Matrix Addition
Ex No.6
Aim:
To write a java program to perform matrix addition.
Code:
import [Link].*;
class MatrixAddition
{
public static void main(String args[])
{
int i, j,r,c;
int a[][]=new int[10][10];
int b[][]=new int[10][10];
int sum[][]=new int[10][10];
Scanner sc=new Scanner([Link]);
[Link]("Enter the number of rows:");
r=[Link]();
[Link]("Enter the number of columns:");
c=[Link]();
[Link]("Enter the first matrix element:");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
a[i][j]=[Link]();
}
}
[Link]("Enter the second matrix elements:");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
b[i][j]=[Link]();
}
}
//Addition of Matrices
for(i=0;i<r;i++)
9
{
for(j=0;j<c;j++)
{
sum[i][j]=a[i][j]+b[i][j];
}
}
[Link]("First Matrix:");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
[Link](a[i][j]+" ");
}
[Link]();
}
[Link]("Second Matrix:");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
[Link](b[i][j]+" ");
}
[Link]();
}
[Link]("Addition of Matrices:");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
[Link](sum[i][j]+" ");
}
[Link]();
}
}
}
10
Output:
11
Matrix Multiplication
Ex No.7
Aim:
To write a java program to perform matrix multiplication.
Code:
import [Link].*;
class MatrixMul
{
public static void main(String args[])
{
int i, j,k,r,c;
int a[][]=new int[10][10];
int b[][]=new int[10][10];
int mul[][]=new int[10][10];
Scanner sc=new Scanner([Link]);
[Link]("Enter the number of rows:");
r=[Link]();
[Link]("Enter the number of columns:");
c=[Link]();
[Link]("Enter the first matrix element:");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
a[i][j]=[Link]();
}
}
[Link]("Enter the second matrix elements:");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
b[i][j]=[Link]();
}
}
//Multiplication of Matrix
12
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
mul[i][j]=0;
for(k=0;k<c;k++)
{
mul[i][j]+=a[i][k]*b[k][j];
}
}
}
[Link]("First Matrix:");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
[Link](a[i][j]+" ");
}
[Link]();
}
[Link]("Second Matrix:");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
[Link](b[i][j]+" ");
}
[Link]();
}
[Link]("Multiplication of Matrices:");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
[Link](mul[i][j]+" ");
}
[Link]();
}
}
}
13
Output:
14
Printing Zero At The Last of an Array
Ex No.8
Aim:
To write a java program to print zero at the last of the array.
Code:
import [Link].*;
class PrintZero
{
public static void main(String args[])
{
int i,j,n,t;
Scanner sc=new Scanner([Link]);
[Link]("Enter the number of element");
n=[Link]();
int a[]=new int[n];
[Link]("Enter the array elements");
for(i=0;i<n;i++)
{
a[i]=[Link]();
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]==0)
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
[Link]("After Sorting Zero at the last of the array");
for(i=0;i<n;i++)
[Link](a[i]);
}
15
}
Output:
16
Student Details Using Class
Ex No.9
Aim:
To write a java program to display student details using class.
Code:
class Student
{
String name,regno;
int m1,m2,m3,tot;
float avg;
void display()
{
[Link]("Student Name: " +name);
[Link]("Register Number: "+regno);
[Link]("Mark1: "+m1);
[Link]("Mark2: "+m2);
[Link]("Mark3: "+m3);
tot=m1+m2+m3;
[Link]("Total: "+tot);
avg=tot/3;
[Link]("Average: "+avg);
}
}
class StudentDetail
{
public static void main(String args[])
{
Student s1=new Student();
[Link]="Rekha";
[Link]="24SUCS98";
s1.m1=98;
s1.m2=90;
s1.m3=86;
[Link]();
[Link]("**************");
Student s2=new Student();
17
[Link]="Varun";
[Link]="24SUCS99";
s2.m1=97;
s2.m2=99;
s2.m3=100;
[Link]();
}
}
Output:
18
Area Calculation Using Method OverLoading
Ex No.10
Aim:
To write a java program to calculate area of different shapes using Method Overloading.
Code:
class AreaCalc
{
int area(int a)
{
return(a*a);
}
int area(int l,int b)
{
return(l*b);
}
float area(float a,float b,float h)
{
return(0.5f*(a+b)*h);
}
}
class MethodOverloading
{
public static void main(String args[])
{
AreaCalc a=new AreaCalc();
[Link]("Area of square:"+[Link](4));
[Link]("Area of Rectangle:"+[Link](6,4));
[Link]("Area of Trapezium:"+[Link](2.0f,2.0f,7.3f));
}
}
19
Output:
20
Volume Calculation Using Constructor Overloading
Ex No.11
Aim:
To write a java program to calculate volume using constructor overloading.
Code:
class Box
{
double width, height, depth;
Box(double w, double h, double d)
{
width = w;
height = h;
depth = d;
}
Box()
{
width=5;
height=4;
depth=6;
}
Box(double len)
{
width = height = depth = len;
}
double volume()
{
return width * height * depth;
}
}
class ConstructorOver
{
public static void main(String args[])
{
Box mybox1 = new Box(10, 20, 15);
21
Box mybox2 = new Box();
Box mycube = new Box(7);
double vol;
vol = [Link]();
[Link]("Volume of mybox1 is " + vol);
vol = [Link]();
[Link]("Volume of mybox2 is " + vol);
vol = [Link]();
[Link]("Volume of mycube is " + vol);
}
}
Output:
22
Object as Parameter
Ex No.12
Aim:
To write a java program to pass object as parameter.
Code:
class Rect
{
int l,b;
Rect(int length, int breadth)
{
l=length;
b=breadth;
}
void area(Rect r1)
{
int a;
a=r1.l*r1.b;
[Link](“Area of rectangle is:” +a);
}
}
class RectObject
{
public static void main(String args[])
{
Rect r1 = new Rect(10,20);
r1. area (r1);
}
}
Output:
23
Employee Salary Details using Single Inheritance
Ex No.14
Aim:
To write a java program to display employee salary details using single inheritance.
Code:
import [Link].*;
class Employee
{
String ename,eno;
float bp;
void getData()
{
Scanner sc=new Scanner([Link]);
[Link]("Enter the employee name");
ename=[Link]();
[Link]("Enter the employee number");
eno=[Link]();
[Link]("Enter the basic pay");
bp=[Link]();
}
}
class Salary extends Employee
{
float hra,da,pf,netpay;
void calc()
{
hra=bp*20/100;
da=bp*50/100;
pf=bp*12/100;
netpay=bp+hra+da-pf;
}
void putData()
{
[Link]("Employee Salary Details");
24
[Link]("*******************");
[Link]("Employee name: "+ename);
[Link]("Employee number: "+eno);
[Link]("Basic Pay: "+bp);
[Link]("House Rent Allowance: "+hra);
[Link]("Daily Allowance: "+da);
[Link]("Provident Fund: "+pf);
[Link]("Net Pay: "+netpay);
}
}
class EmpDetails
{
public static void main(String args[])
{
Salary s= new Salary();
[Link]();
[Link]();
[Link]();
}
}
Output:
25
Student Details Using Multilevel Inheritance
Ex No.15
Aim:
To write a java program to display student details using multilevel inheritance.
Code:
class Students
{
int sno;
String sname;
void setstud(int no,String name)
{
sno=no;
sname=name;
}
void putstud()
{
[Link]("Student no:"+sno);
[Link]("Student name:"+sname);
}
}
class Marks extends Students
{
int mark1,mark2,mark3;
void setmarks(int m1,int m2,int m3)
{
mark1=m1;
mark2=m2;
mark3=m3;
}
void putmarks()
{
[Link]("Mark1:"+mark1);
[Link]("Mark2:"+mark2);
[Link]("Mark3:"+mark3);
26
}
}
class FinalTotal extends Marks
{
int tot;
float avg;
void calc()
{
tot=mark1+mark2+mark3;
avg=tot/3;
}
void puttot()
{
[Link]("Total:"+tot);
[Link]("Average:"+avg);
}
}
class StudentDetail1
{
public static void main(String args[])
{
FinalTotal f=new FinalTotal();
[Link](101,"Sneha");
[Link](90,96,98);
[Link]();
[Link]();
[Link]();
[Link]();
}
}
Output:
27
Method Overriding
Ex No.16
Aim:
To write a java program to implement Method Overriding.
Code:
class Shape
{
double d1,d2;
Shape(double a,double b)
{
d1=a;
d2=b;
}
double area()
{
return 0;
}
}
class Rectangle extends Shape
{
Rectangle(double a,double b)
{
super(a,b);
}
double area()
{
return d1*d2;
}
}
class Triangle extends Shape
{
Triangle(double a,double b)
{
super(a,b);
}
double area()
28
{
return d1*d2/2;
}
}
class MethodOverriding
{
public static void main(String args[])
{
Shape s=new Shape(10,20);
Rectangle r=new Rectangle(15,5);
Triangle t=new Triangle(5,10);
[Link]("Area of Undefined Shape:"+[Link]());
[Link]("Area of Rectangle:"+[Link]());
[Link]("Area of Triangle:"+[Link]());
}
}
Output:
29
Dynamic Method Dispatch
Ex No.17
Aim:
To write a java program to implement dynamic method dispatch.
Code:
class Shape
{
double d1,d2;
Shape(double a,double b)
{
d1=a;
d2=b;
}
double area()
{
return 0;
}
}
class Rectangle extends Shape
{
Rectangle(double a,double b)
{
super(a,b);
}
double area()
{
return d1*d2;
}
}
class Triangle extends Shape
{
Triangle(double a,double b)
{
super(a,b);
}
double area()
{
30
return d1*d2/2;
}
}
class Dynamic
{
public static void main(String args[])
{
Shape s=new Shape(10,20);
Rectangle r=new Rectangle(15,5);
Triangle t=new Triangle(5,10);
Shape sref;
sref=s;
[Link]("Area of undefined Shape:"+[Link]());
sref=r;
[Link]("Area of Rectangle:"+[Link]());
sref=t;
[Link]("Area of triangle:"+[Link]());
}
}
Output:
31
Arithmetic Operations using Package
[Link]
Aim:
To write a java program to perform arithmetic operation using package.
Code:
//addition
package addition;
import [Link].*;
public class Add
{
int a,b,c;
Scanner s=new Scanner([Link]);
public void getdata()
{
[Link]("ADDITION");
[Link]("enter A value:");
a=[Link]();
[Link]("enter B value:");
b=[Link]();
c=a+b;
[Link]("Addition value is:"+c);
}
}
//subtraction
package subtraction;
import [Link].*;
public class Subtract
{
int a,b,c;
Scanner s=new Scanner([Link]);
public void getdata()
{
[Link]("SUBTRACTION");
[Link]("enter A value:");
a=[Link]();
32
[Link]("enter B value:");
b=[Link]();
c=a-b;
[Link]("Subtraction value is:"+c);
}
}
//multiplication
package multiplication;
import [Link].*;
public class Mul
{
int a,b,c;
Scanner s=new Scanner([Link]);
public void getdata()
{
[Link]("MULTIPLICATION");
[Link]("enter A value:");
a=[Link]();
[Link]("enter B value:");
b=[Link]();
c=a*b;
[Link]("Multiplication value is:"+c);
}
}
//division
package division;
import [Link].*;
public class Div
{
int a,b,c;
Scanner s=new Scanner([Link]);
public void getdata()
{
[Link]("DIVISION");
[Link]("enter A value:");
a=[Link]();
[Link]("enter B value:");
b=[Link]();
c=a/b;
33
[Link]("Division value is:"+c);
}
}
//pack
import [Link];
import [Link];
import [Link];
import [Link];
class Pack
{
public static void main(String args[])
{
Add a=new Add();
[Link]();
Subtract s=new Subtract();
[Link]();
Mul m=new Mul();
[Link]();
Div d=new Div();
[Link]();
}
}
34
Output:
35
Area Calculation using Interface
[Link]
Aim:
To write a java program to perform area calculation using interface
Code:
import [Link].*;
interface Shapes
{
void area (double b,double h);
}
class Triangle implements Shapes
{
public void area (double b,double h)
{
double a;
a=0.5*b*h;
[Link]("Base:"+b);
[Link]("Height:"+h);
[Link]("Area of Triangle:"+a);
}
}
class Parallelogram implements Shapes
{
public void area (double b,double h)
{
double a;
a=b*h;
[Link]("Base:"+b);
[Link]("Height:"+h);
[Link]("Area of Parallelogram:"+a);
}
}
class AreaInterface
{
public static void main(String args[])
{
Triangle t=new Triangle();
[Link](12.5,10);
36
Parallelogram p=new Parallelogram();
[Link](16.5,13.5);
}
}
Output:
37
Factorial of a Number using Recursion
[Link]
Aim:
To write a java program to perform factorial of a number using recursion.
Code:
import [Link].*;
class Factorial
{
int fact(int n)
{
if(n==1)
return 1;
else
return n*fact(n-1);
}
}
class FactNumber
{
public static void main(String args[])
{
Factorial f=new Factorial();
Scanner sc=new Scanner([Link]);
int n;
[Link]("Enter the number:");
n=[Link]();
[Link]("Factorial Value is "+[Link](n));
}
}
Output:
38
Built-in Exception
[Link]
Aim:
To write a java program for built-in exception
Code:
class MultiCatch
{
public static void main(String args[])
{
try
{
int a=[Link];
[Link]("a="+a);
int b=42/a;
int c[]={1};
c[42]=99;
}
catch(ArithmeticException e)
{
[Link]("Divide by Zero"+e);
}
catch( ArrayIndexOutOfBoundsException e)
{
[Link]("Array Index out of bound:"+e);
}
finally
{
[Link]("After try/catch blocks");
}
}
}
39
Output:
40
User Defined Exception
[Link]
Aim:
To write a java program for user defined exception.
Code:
import [Link].*;
class Numberx extends Exception
{
public String toString()
{
return("Number should not be negative");
}
}
public class SignException
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
[Link]("Enter the number:");
try
{
int n,s=0;
n=[Link]();
if(n<0)
throw new Numberx();
else
{
while(n!=0)
{
int r=n%10;
s=s*10+r;
n=n/10;
}
[Link]("Reverse of the given number is" +s);
}
}
41
catch(Numberx e)
{
[Link]("EXCEPTION: " +e);
}
}
}
OUTPUT:
42
Multithreaded Programming using Runnable interface
[Link]
Aim:
To write a java program for multithreaded programming using runnable interface.
Code:
class Ethread implements Runnable
{
int i;
public void run()
{
for(i=1;i<=10;i++)
{
if(i%2==0)
[Link]("EVEN NUMBER:"+i);
}
}
}
class Fthread implements Runnable
{
int f1=0,f2=1,f3,i;
public void run()
{
[Link]("Fib:"+f1);
[Link]("Fib:"+f2);
for(i=2;i<10;i++)
{
f3=f1+f2;
[Link]("Fib:"+f3);
f1=f2;
f2=f3;
}
}
}
class MultiThreads
{
public static void main(String args[])
{
43
Thread ct=[Link]();
[Link]("The main thread is:"+[Link]());
Ethread et=new Ethread();
Fthread ft=new Fthread();
Thread et1=new Thread(et,"Even Number");
Thread ft1=new Thread(ft,"Fibonacci Number");
[Link]();
[Link]("The thread created is:"+[Link]());
[Link]();
[Link]("The thread created is:"+[Link]());
}
}
Output:
44
String Manipulation
[Link]
Aim:
To write a java program for String manipulation.
Code:
import [Link].*;
class StringOperations
{
public static void main(String args[])throws IOException
{
DataInputStream dis=new DataInputStream([Link]);
StringBuffer sb=new StringBuffer("Hello");
[Link]("STRING MANIPULATION");
[Link]("************************");
[Link]("Enter two strings");
String str1=[Link]();
String str2=[Link]();
[Link]("Buffer:"+sb);
[Link]("length:"+[Link]());
[Link]("capacity:"+[Link]());
[Link]("insert:"+[Link](1,str1));
[Link]("delete:"+[Link](1,3));
[Link]("reverse:"+[Link]());
[Link]("concatenation:"+[Link](str2));
[Link]("uppercase:"+[Link]());
[Link]("lowercase:"+[Link]());
[Link]("replace:"+[Link]('a','x'));
[Link]("index of with place:"+[Link]('n'));
[Link]("substring:"+[Link](2));
}
}
45
Output:
46
Animation
[Link]
Aim:
To write a java program for animation using applet.
Code:
import [Link].*;
import [Link].*;
/*<applet code=Animation width=500 height=500>
</applet>*/
public class Animation extends Applet
{
public void paint(Graphics g)
{
int a=150,b=150,c=10,d=10;
[Link]([Link]);
for(int i=0;i<15;i++)
{
try
{
[Link](500);
}
catch(InterruptedException ex){}
[Link](a,b,c,d);
a-=10;
b-=10;
c+=8;
d+=8;
}
}
}
47
Output:
48
Font and Color Class
[Link]
Aim:
To write a java program to display many fonts using applet.
Code:
import [Link].*;
import [Link].*;
/*<applet code=ManyFont width=400 height=400></applet>*/
public class ManyFont extends Applet
{
public void paint(Graphics g)
{
setBackground([Link]);
Font f=new Font("Times New Roman",[Link],18);
Font fb=new Font("verdana",[Link],18);
Font fi=new Font("system",[Link],18);
Font fbi=new Font("Ink free",[Link]+[Link],18);
[Link]([Link]);
[Link](f);
[Link]("This is Plain text",10,25);
[Link]([Link]);
[Link](fb);
[Link]("This is Bold text",10,50);
[Link]([Link]);
[Link](fi);
[Link]("This is Italic text",10,75);
[Link]([Link]);
[Link](fbi);
[Link]("This is Bold and Italic text",10,100);
[Link]([Link]);
}
}
49
Output:
50
Draw Shapes using Graphical Method
[Link]
Aim:
To write java program to draw shapes using Graphical methods.
Code:
import [Link].*;
import [Link].*;
/*<applet code=Shape width=500 height=500> </applet>*/
public class Shape extends Applet
{
public void paint(Graphics g)
{
int xpoints[]={400,200,400,200,400};
int ypoints[]={400,400,200,200,400};
int num=5;
[Link]([Link]);
[Link](xpoints,ypoints,num);
[Link](10,10,50,50);
[Link]([Link]);
[Link](10,60,40,30);
[Link]([Link]);
[Link](60,10,80,80);
[Link]([Link]);
[Link](10,100,80,50,10,10);
[Link]([Link]);
[Link](20,110,60,30,5,5);
[Link]([Link]);
[Link]("Different Shapes",150,180);
[Link](230,10,200,150);
[Link]([Link]);
[Link](245,25,100,100);
[Link](80,300,80,80,0,180);
[Link]([Link]);
[Link](100,100,70,90,0,270);
}
}
51
Output:
52
AWT Basic Controls
[Link]
Aim:
To write a java program to display student details form using AWT basic controls.
Code:
//Demonstrate AWT Controls
import [Link].*;
import [Link].*;
import [Link].*;
/*
<applet code=Student2 width=500 height=500>
</applet>
*/
public class Student2 extends Applet implements ActionListener
{
String msg;
Label l1=new Label("Name:",[Link]);
Label l2=new Label("Gender:",[Link]);
Label l3=new Label("Address:",[Link]);
Label l4=new Label("Course:",[Link]);
Label l5=new Label("Semester:",[Link]);
TextField t1=new TextField();
CheckboxGroup cbg=new CheckboxGroup();
Checkbox ck1=new Checkbox("Male",false,cbg);
Checkbox ck2=new Checkbox("Female",false,cbg);
TextArea t2=new TextArea();
Choice course=new Choice();
List sem=new List();
Button b1=new Button("Save");
public void init()
{
setBackground([Link]);
setForeground([Link]);
setLayout(null);
add(l1);
add(l2);
add(l3);
53
add(l4);
add(l5);
add(t1);
add(t2);
add(ck1);
add(ck2);
add(course);
add(sem);
add(b1);
[Link](this);
[Link]("[Link] CS");
[Link]("[Link] Maths");
[Link]("[Link] Physics");
[Link]("BA English");
[Link]("[Link]");
[Link]("1");
[Link]("2");
[Link]("3");
[Link]("4");
[Link]("5");
[Link]("6");
[Link](25,60,90,20);
[Link](25,120,90,20);
[Link](25,180,90,20);
[Link](25,240,90,20);
[Link](25,300,90,20);
[Link](120,60,180,20);
[Link](120,120,60,20);
[Link](180,120,60,20);
[Link](120,180,180,50);
[Link](120,240,90,20);
[Link](120,300,90,20);
[Link](120,350,50,30);
}
public void paint(Graphics g)
{
[Link](msg,200,400);
}
54
public void actionPerformed(ActionEvent ae)
{
if([Link]().equals("Save"))
{
msg="Student details saved!";
setForeground([Link]);
}
}
}
Output:
55
Grid layout
[Link]
Aim:
To write a program a java program to display grid layout.
Code:
import [Link].*;
import [Link].*;
/*
<applet code ="GridLayoutDemo" width=300 height=200>
</applet>
*/
public class GridLayoutDemo extends Applet
{
static final int n=4;
public void init()
{
setLayout(new GridLayout(n,n));
setFont(new Font("SansSerif",[Link],24));
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
int k=i*n +j;
if(k>0)
add(new Button(" " + k));
}
}
}
}
56
Output:
57