0% found this document useful (0 votes)
60 views23 pages

Lab Programs Oop

The document contains code for 6 Java lab programs: 1. A student class that reads student details from input, calculates average and grade. 2. A transpose class that reads a matrix and finds its transpose. 3. A complex number class with methods to read complex numbers and perform addition and subtraction. 4. A class hierarchy with staff, teaching staff and non-teaching staff classes to store and display employee details. 5. A package declaration and student class to store student details, calculate total marks and display results. 6. No code shown for the 6th lab program.

Uploaded by

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

Lab Programs Oop

The document contains code for 6 Java lab programs: 1. A student class that reads student details from input, calculates average and grade. 2. A transpose class that reads a matrix and finds its transpose. 3. A complex number class with methods to read complex numbers and perform addition and subtraction. 4. A class hierarchy with staff, teaching staff and non-teaching staff classes to store and display employee details. 5. A package declaration and student class to store student details, calculate total marks and display results. 6. No code shown for the 6th lab program.

Uploaded by

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

LAB PROGRAMS

Lab Program1: Student details


import java.util.Scanner;

class student
{
int rno,sum;
String name;
int marks[]=new int[6];
float avg;
char grade;

student()
{
rno=101;
name="xyz";
marks[0]=78;marks[1]=89;marks[2]=98;
marks[3]=87;marks[4]=88;marks[5]=76;
}
void read()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter student number:");
rno=sc.nextInt();
System.out.println("Enter student name:");
sc.nextLine();
name=sc.nextLine();
System.out.println("Enter six subject marks:");
for(int i=0;i<6;i++)
{
marks[i]=sc.nextInt();
}
}
void display()
{
System.out.println("Student roll number: "+rno);
System.out.println("Student name: "+name);
System.out.println("Student six subject marks:");
for(int i=0;i<6;i++)
{
System.out.println(marks[i]);
}
System.out.println("Student total marks: "+sum);
System.out.println("Student average marks:"+avg);
System.out.println("Student grade: "+grade);
}
void average()
{
sum=0;
for(int i=0;i<6;i++)
sum+=marks[i];
avg=sum/6.0f;
}
void gradecalc()
{
switch((int)avg/10)
{
case 10:
case 9: grade='A';break;
case 8:
case 7: grade='B';break;
case 6:
case 5: grade='C';break;
case 4:
case 3: grade='D';break;
case 2:
case 1:
case 0: grade='F';break;
}
}
}

class studentdemo
{
public static void main(String[] args)
{
/*student s=new student();
s.average();
s.gradecalc();
s.display();
student s1=new student();
s1.read();
s1.average();
s1.gradecalc();
s1.display();*/
int n;
Scanner sc=new Scanner(System.in);
System.out.println("Enter number of students:");
n=sc.nextInt();
student s[]=new student[n];
for(int i=0;i<n;i++)
{
s[i]=new student();
s[i].read();
s[i].average();
s[i].gradecalc();
s[i].display();
}
}
}
Lab Program 2: Transpose of matrix
import java.util.Scanner;

class transpose
{
int m,n;
int x[][];
transpose()
{
m=3;
n=3;
}
transpose(int m,int n)
{
this.m=m;
this.n=n;
}
void read()
{
Scanner sc=new Scanner(System.in);
x=new int[m][n];
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
x[i][j]=sc.nextInt();
}
void display()
{
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(x[i][j]+" ");
}
System.out.println();
}
}
void transposeresult()
{
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
System.out.print(x[j][i]+" ");
}
System.out.println();
}
}
}

class transposedemo
{
public static void main(String[] args)
{
int m,n;
Scanner sc=new Scanner(System.in);
System.out.println("Enter size of matrix:");
m=sc.nextInt();
n=sc.nextInt();
transpose t=new transpose(m,n);
System.out.println("Enter "+m+"*"+n+" matrix:");
t.read();
System.out.println("Given "+m+"*"+n+" matrix:");
t.display();
System.out.println("Transpose:");
t.transposeresult();
}
}

Lab Program 3: Complex number operations


import java.util.Scanner;

class complex
{
int real,img;
complex()
{
real=2;
img=3;
}
complex(int real,int img)
{
this.real=real;
this.img=img;
}
void read()
{
Scanner sc=new Scanner(System.in);
real=sc.nextInt();
img=sc.nextInt();
}
void display()
{
System.out.println(real+"+i"+img);
}
complex sum(complex c1,complex c2)
{
complex result=new complex();
result.real=c1.real+c2.real;
result.img=c1.img+c2.img;
return result;
}
complex sub(complex c1,complex c2)
{
complex result=new complex();
result.real=c1.real-c2.real;
result.img=c1.img-c2.img;
return result;
}
}

class complexdemo
{
public static void main(String[] args)
{
complex c1=new complex();
complex c2=new complex();
complex c3=new complex();
System.out.println("Enter real and imaginary values of first
complex number");
c1.read();
System.out.println("Enter real and imaginary values of second
complex number");
c2.read();
//c1.display();
//c2.display();
System.out.print("First complex number:");
c1.display();
System.out.print("Second complex number:");
c2.display();
c3=c3.sum(c1,c2);
System.out.print("Addition=");
c3.display();
c3=c3.sub(c1,c2);
System.out.print("Subraction=");
c3.display();
}
}

Lab Program 4:

class Staff
{
String name, addr;
int age;
Staff()
{
name="Gopal";
age=28;
addr="kurnool";
}
Staff(String n,int a,String ad)
{
name=n;
age=a;
addr=ad;
}
void Sdisplay()
{
System.out.println("Name: "+name);
System.out.println("Age: "+age);
System.out.println("Address: "+addr);
}
}
class NTstaff extends Staff
{
String qual;
int yoe;
int salary;
NTstaff()
{
qual="B.Tech";
yoe=0;
salary=10000;
}
NTstaff(String n,int a,String ad,String q,int y,int s)
{
super(n,a,ad);
qual=q;
yoe=y;
salary=s;
}
void NTdisplay()
{
super.Sdisplay();
System.out.println("Qualification: "+qual);
System.out.println("Years of experience: "+yoe);
System.out.println("Salary: "+salary);
}
}
class Tstaff extends Staff
{
String qual;
int yoe;
Tstaff()
{
qual="M.Tech";
yoe=2;
}
Tstaff(String n,int a,String ad,String q,int y)
{
super(n,a,ad);
qual=q;
yoe=y;
}
void Tdisplay()
{
super.Sdisplay();
System.out.println("Qualification: "+qual);
System.out.println("Years of experience: "+yoe);
}
}
class RTstaff extends Tstaff
{
double bs,hra,da,tax,gs;
RTstaff()
{
bs=16500;
hra=0.1*bs;
da=0.5*bs;
tax=0.15*bs;
}
RTstaff(String n,int a, String ad,String q,int y, int b)
{
super(n,a,ad,q,y);
bs=b;
hra=0.1*bs;
da=0.5*bs;
tax=0.15*bs;
}
void calcgs()
{
super.Tdisplay();
gs=bs+hra+da-tax;
System.out.println("Gross salary: "+gs);
}
}
class TTstaff extends Tstaff
{
double cs;
TTstaff()
{
cs=23000;
}
TTstaff(String n,int a, String ad,String q,int y, int s)
{
super(n,a,ad,q,y);
cs=s;
}
void calccs()
{
super.Tdisplay();
System.out.println("Consolidated salary: "+cs);
}
}
class inherlab
{
public static void main(String args[])
{
RTstaff r1=new RTstaff();
System.out.println("-------------------------------");
System.out.println("Regular Teaching Staff Details:");
System.out.println("-------------------------------");
r1.calcgs();
RTstaff r2=new
RTstaff("Ram",35,"Hyderabad","PhD",5,40000);
System.out.println("*******************************");
r2.calcgs();
TTstaff t1=new TTstaff();
System.out.println("-------------------------------");
System.out.println("Temporary Teaching Staff Details:");
System.out.println("-------------------------------");
t1.calccs();
TTstaff t2=new TTstaff("Raju",29,"Mumbai","PhD",5,45000);
System.out.println("*******************************");
t2.calccs();
NTstaff n1=new NTstaff();
System.out.println("-------------------------------");
System.out.println("Non-Teaching Staff Details:");
System.out.println("-------------------------------");
n1.NTdisplay();
NTstaff n2=new
NTstaff("Swathi",25,"Banglore","B.Tech",3,15000);
System.out.println("*******************************");
n2.NTdisplay();
}
}

Lab Program 6: Package


package std;

public class Student


{
String name;
int rno,m1,m2,m3;
char grade;
int total;
public Student(String s,int no,int a,int b,int c)
{
name=s;
rno=no;
m1=a;
m2=b;
m3=c;
}
public int getTotal()
{
total=m1+m2+m3;
return total;
}
public void display(double avg,char grade)
{
System.out.println("--------------------------------------");
System.out.println("Student details:");
System.out.println("Name of the student: "+name);
System.out.println("Roll num of the student: "+rno);
System.out.println("Marks in three subjects: "+m1+"\t"+m2+"\t"+m3);
System.out.println("Total marks : "+total);
System.out.println("Average marks: "+avg);
System.out.println("Grade: "+grade);
}
}

package std.grd;

public class Grade


{
int total;
double avg;
char grade;
public double average(int t)
{
total=t;
avg=total/3.0;
return avg;
}
public char getGrade()
{
if(avg>=70)
grade='A';
else if(avg>=50)
grade='B';
else if(avg>=35)
grade='C';
else
grade='F';
return grade;
}
}

import std.*;
import std.grd.*;
import java.util.Scanner;

class StudentResult
{
public static void main(String arg[ ])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter Name of the student:");
String name=sc.nextLine();
System.out.println("Enter Roll number of the student:");
int no=sc.nextInt();
System.out.println("Enter Marks in first subject:");
int s1=sc.nextInt();
System.out.println("Enter Marks in second subject:");
int s2=sc.nextInt();
System.out.println("Enter Marks in third subject:");
int s3=sc.nextInt();
Student s=new Student(name,no,s1,s2,s3);
int t=s.getTotal();
Grade gr=new Grade();
double avg=gr.average(t);
char g=gr.getGrade();
s.display(avg,g);
}
}

Lab Program 8: Strings

package practice;

import java.util.Scanner;

public class StringLab {

public static void main(String[] args) {


// TODO Auto-generated method stub
String s = "Welcome! This is CS212 Java Course";
System.out.println("The given sentence is :\n"+s);
System.out.println("After converting to lowercase letters
:\n"+s.toLowerCase());
System.out.println("After converting to uppercase letters
:\n"+s.toUpperCase());
System.out.println("Index of the word Course is :
"+s.indexOf("Course"));
s=s.replace("CS212","CSE212");
System.out.println("Sentence after replacing CS212 with
CSE212 is\n"+s);
int sum=0;
for(int i=0;i<s.length();i+=2)
sum+=s.charAt(i);
System.out.println("Sum of ASCII values at even position
is : "+sum);
System.out.println("Type your name:");
Scanner sc=new Scanner(System.in);
String name=sc.nextLine(); // Ramana Maharshi
//int sp=name.indexOf(" ");
//System.out.println("Your name is :
"+name.substring(sp+1)+","+name.charAt(0)+".");
String str[]=name.split(" ");
System.out.println("Your name is :
"+str[1]+","+str[0].charAt(0)+".");
}

Lab Program 9:
package practice;

import java.util.InputMismatchException;
import java.util.Scanner;

public class Exceptiondemo7 {

public static void main(String[] args) {


// TODO Auto-generated method stub
try
{
baoperations();
}
catch(ArithmeticException e)
{
System.out.println("Arithmetic Exception Caught,
please give the value other than zero as second integer");
System.out.println("Exception caught: "+e);
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("\nException caught: "+e);
}
catch(InputMismatchException e)
{
System.out.println("Excetion caught: "+e);
}
catch(Exception e)
{
System.out.println("\nException caught: "+e);
}
finally
{
System.out.println("Finally block executed.");
}
}

private static void baoperations() throws ArithmeticException,


ArrayIndexOutOfBoundsException, InputMismatchException{
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int fn,sn;
int x[]= {10,20,30,40,50};
System.out.println("Enter two integers: ");
fn=sc.nextInt();
sn=sc.nextInt();
System.out.println("Addition: "+(fn+sn));
System.out.println("Subtraction: "+(fn-sn));
System.out.println("Multiplication: "+(fn*sn));
System.out.println("Divison: "+(fn/sn));
for(int i=0;i<=x.length;i++)
System.out.print(x[i]+" ");
System.out.println("Program Executed without
exception.");
sc.close();
}

Lab Program 10:


package practice;

import java.util.Scanner;

public class ExceptionLab {

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
System.out.println("Enter the name of the student: ");
String name=sc.nextLine();
System.out.println("Enter course name : ");
String course=sc.nextLine();
System.out.println("Enter Registered number XXXX format:
");
int regnum=sc.nextInt();
try
{
studentDetails(name,course,regnum);
}
catch(SeatsFilledException e)
{
System.out.println("Exception caught: "+e);
}
sc.close();
}
public static void studentDetails(String n,String c,int r)
throws SeatsFilledException
{
if((r%100)>60)
throw new SeatsFilledException(r%100);
System.out.println("Details of student are: ");
System.out.println("Name of the student : "+n);
System.out.println("Course name : "+c);
System.out.println("Registered number : "+r);
}
}
class SeatsFilledException extends Exception
{
/**
*
*/
private static final long serialVersionUID = 1L;
/**
*
*/
int maxcount;
SeatsFilledException(int c)
{
maxcount=c;
}
public String toString()
{
return "Seats are filled, limit exceeded! "+maxcount;
}
}

Lab Program 11: Multi-thread program using Synchronization


Concept
package practice;

public class ThreadLab1 {

public static void main(String[] args) {


// TODO Auto-generated method stub
resource ob=new resource();
Mthread1 t1=new Mthread1(ob);
Mthread2 t2=new Mthread2(ob);
System.out.println("Thread1 started");
t1.start();
System.out.println("Thread2 started");
t2.start();
}

}
class resource
{
synchronized void MTable(int n)
{
System.out.println(n+"'s Multiplication table:");
for(int i=1;i<=10;i++)
{
System.out.println(n+" * "+i+" = "+(n*i));
try
{
Thread.sleep(1000);
}
catch(InterruptedException e)
{
System.out.println(e);
}
}
}
}

class Mthread1 extends Thread


{
resource r;
Mthread1(resource ob)
{
r=ob;
}
public void run()
{
r.MTable(2);
}
}

class Mthread2 extends Thread


{
resource r;
Mthread2(resource ob)
{
r=ob;
}
public void run()
{
r.MTable(5);
}
}

Lab Program 12: Producer-Consumer Problem


package practice;

public class ThreadLab2 {

public static void main(String[] args) {


// TODO Auto-generated method stub
Queue q = new Queue();
Producer p = new Producer(q);
Consumer c = new Consumer(q);
p.start();
c.start();
}

class Queue //Producer-consumer problem using Interthread


communication
{
int n;
boolean full = false;
synchronized void get()
{
if(full==false)
{
try
{
wait();
}
catch(InterruptedException e)
{
System.out.println("InterruptedException
caught");
}
}
System.out.println("Consumed: " + n);
full = false;
notify();
}
synchronized void put(int n)
{
if(full==true)
{
try
{
wait();
}
catch(InterruptedException e)
{
System.out.println("InterruptedException
caught");
}
}
this.n = n;
full = true;
System.out.println("Produced: " + n);
notify();
}
}

class Producer extends Thread


{
Queue q;
Producer(Queue q)
{
this.q = q;
}
public void run()
{
int i = 0;
while(true)
{
q.put(i++);
/*if(i==10)
break;*/
}
}
}

class Consumer extends Thread


{
Queue q;
Consumer(Queue q)
{
this.q = q;
}
public void run()
{
while(true)
{
q.get();
}
}
}

Lab Program 13: Files


13.a:
package practice;

import java.io.*;

public class FileLab1 {

public static void main(String[] args) throws IOException{


// TODO Auto-generated method stub
FileWriter fw=new FileWriter("student.txt");
BufferedWriter bw=new BufferedWriter(fw);
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter number of the students:");
int n;
n=Integer.parseInt(br.readLine());
String s;
bw.write(" Number "+" Name "+" CGPA\n");
bw.write(" ---------- "+" -------- "+" ------- \n");
for(int i=0;i<n;i++)
{
System.out.println("Enter Student "+(i+1)+"
details:");
System.out.println("Enter Student Number:");
s=br.readLine();
bw.write(" "+s+" ");
System.out.println("Enter Student Name:");
s=br.readLine();
bw.write(" "+s+" ");
System.out.println("Enter Student CGPA:");
s=br.readLine();
bw.write(" "+s);
bw.write("\n");
}
bw.close();
System.out.println("The Student data is successfully
written to the file.");
}

13.b:
package practice;

import java.io.*;

public class FileLab2 {

public static void main(String[] args) throws IOException{


// TODO Auto-generated method stub
FileReader fr=new FileReader("student.txt");
BufferedReader br=new BufferedReader(fr);
System.out.println("The student details are:");
String s;
while((s=br.readLine())!=null) // End of file is null
value
System.out.println(s);
br.close();
System.out.println("Student data is successfully read
from the file.");
}

13.c:
package practice;

import java.io.*;

public class FileLab3 {

public static void main(String[] args) throws IOException{


// TODO Auto-generated method stub
FileReader fr=new FileReader("student.txt");
FileWriter fw=new FileWriter("student_copy.txt");
FileReader fr1=new FileReader("student_copy.txt");
BufferedReader br=new BufferedReader(fr);
BufferedReader br1=new BufferedReader(fr1);
BufferedWriter bw=new BufferedWriter(fw);
String s;
while((s=br.readLine())!=null)
{
bw.write(s);
bw.write("\n");
}
br.close();
bw.close();
System.out.println("Student data is copied from one
file to another file successfully.");
System.out.println("Student details:");
while((s=br1.readLine())!=null)
{
System.out.println(s);
}
br1.close();
fr1.close();
}

Lab Program 14: Applets


package Practice;

import java.awt.*;
import java.applet.Applet;

public class AppletLab extends Applet{


Font f;
public void init()
{
f=new Font("Verdana",Font.BOLD,28);
}
public void paint(Graphics g)
{
g.setColor(Color.blue);
g.setFont(f);
g.drawString("We are CSE students of GPREC",30,50);
g.setColor(Color.red);
g.drawLine(50,60,100,200);
g.drawRect(150,100,200,150);
g.fillRect(200,300,80,60);
g.drawRoundRect(10,250,80,50,10,10);
g.drawRect(10, 350, 100, 100);
g.fillRect(200, 450, 100, 100);
g.drawRoundRect(60, 470, 100, 100, 10, 10);
g.setColor(Color.cyan);
g.drawOval(300,150,30,60);
g.fillOval(170,150,30,60);
g.drawOval(220,150,60,60);
g.fillOval(270,200,30,30);
g.setColor(Color.green);
int x[ ]={800,700,600,500};
int y[ ]={150,120,100,120};
int n=4;
g.drawPolygon(x,y,n);
g.setColor(Color.MAGENTA);
g.setFont(f);
g.drawString("Working with Graphics class using
Applet",100,650);
}
}

Lab Program 15:

15.a)
package Practice;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class AWTLab1 extends Applet implements KeyListener{


String msg="Key Pressed: ";
Font f;
public void init()
{
setBackground(Color.DARK_GRAY);
setSize(500,500);
addKeyListener(this);
}
public void keyPressed(KeyEvent ke)
{
showStatus("Key pressed");
}
public void keyReleased(KeyEvent ke)
{
showStatus("Key released");
}
public void keyTyped(KeyEvent ke)
{
msg+=ke.getKeyChar();
repaint();
}
public void paint(Graphics g)
{
f = new Font("Verdana",Font.ITALIC,24);
g.setFont(f);
g.setColor(Color.RED);
g.drawString(msg,100,150);
}
}
15.b)
package Practice;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class AWTLab2 extends Applet implements MouseListener,


MouseMotionListener{
String msg="";
int mx=0;
int my=10;
Font f;
public void init()
{
setBackground(Color.DARK_GRAY);
setSize(500,500);
addMouseListener(this);
addMouseMotionListener(this);
}
public void mouseClicked(MouseEvent me)
{
mx=10;
my=150;
msg="Mouse clicked";
repaint();
}
public void mouseEntered(MouseEvent me)
{
mx=10;
my=100;
msg="Mouse entered";
repaint();
}
public void mouseExited(MouseEvent me)
{
mx=0;
my=50;
msg="Mouse exited";
repaint();
}
public void mouseReleased(MouseEvent me)
{
mx=me.getX();
my=me.getY();
msg="Mouse released: "+mx+","+my;
showStatus(msg);
repaint();
}
public void mousePressed(MouseEvent me)
{
mx=me.getX();
my=me.getY();
msg="Mouse pressed: "+mx+", "+my;
showStatus(msg);
repaint();
}
public void mouseDragged(MouseEvent me)
{
showStatus("Mouse dragged: "+me.getX()+", "+me.getY());
}
public void mouseMoved(MouseEvent me)
{
showStatus("Mouse moved: "+me.getX()+", "+me.getY());
}
public void paint(Graphics g)
{
f = new Font("Verdana",Font.ITALIC,24);
g.setFont(f);
g.setColor(Color.RED);
g.drawString(msg,mx,my);
}
}

Lab Program 16:


16.a)
package Practice;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class AWTLab3 extends Applet implements ActionListener{


Label l1,l2,l3;
TextField t1,t2;
Button b1,b2;
Font f;
public void init()
{
setForeground(Color.ORANGE);
setBackground(Color.DARK_GRAY);
setSize(600,500);
l1 = new Label("Enter a value: ");
l2 = new Label("Factorial:");
l3 = new Label("Applet application to find Factorial of a
number");
t1 = new TextField(10);
t2 = new TextField(10);
b1 = new Button("Calculate");
b2 = new Button("Clear");
f = new Font("Arial",Font.BOLD,24);
setFont(f);
add(l3);
add(l1);
add(t1);
add(b1);
add(b2);
add(l2);
add(t2);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
int n=Integer.parseInt(t1.getText());
int fact=1;
if(ae.getSource()==b1)
{
if(n==0||n==1)
{
fact=1;
t2.setText(String.valueOf(fact));
}
else
{
for(int i=1;i<=n;i++)
fact=fact*i;
t2.setText(String.valueOf(fact));
}
}
else if(ae.getSource()==b2)
{
t1.setText("");
t2.setText("");
}
}
}
16.b)
package Practice;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class AWTLab4 extends Applet implements ActionListener{


Label l1,l2,l3,l4,l5,l6,l7;
List lt1,lt2;
TextField t1,t2,t3;
Choice c1,c2;
Button b1;
String msg="";
Font f;
public void init()
{
setForeground(Color.ORANGE);
setBackground(Color.DARK_GRAY);
setSize(600,1000);
l1=new Label("Name:");
l2=new Label("Roll Number:");
l3=new Label("CGPA:");
l4=new Label("Gender:");
l5=new Label("Semester:");
l6=new Label("Branch:");
l7=new Label("Select languages:");
t1=new TextField(25);
t2=new TextField(15);
t3=new TextField(15);
c1=new Choice();
c1.addItem("Male");
c1.addItem("Female");
c2=new Choice();
c2.addItem("I");
c2.addItem("II");
c2.addItem("III");
c2.addItem("IV");
c2.addItem("V");
c2.addItem("VI");
c2.addItem("VII");
c2.addItem("VIII");
lt1=new List(4,false);
lt2=new List(3,true);
lt1.add("CSE");
lt1.add("ECE");
lt1.add("EEE");
lt1.add("ME");
lt2.add("C");
lt2.add("C++");
lt2.add("Java");
b1=new Button("Submit");
f = new Font("Arial",Font.BOLD,24);
setFont(f);
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(l4);
add(c1);
add(l5);
add(c2);
add(l6);
add(lt1);
add(l7);
add(lt2);
add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
repaint();
}
public void paint(Graphics g)
{
g.setFont(f);
g.setColor(Color.YELLOW);
msg="Your Name is : "+t1.getText();
g.drawString(msg,20,400);
msg="Your Roll Number is : "+t2.getText();
g.drawString(msg, 20,430);
msg="CGPA is : "+t3.getText();
g.drawString(msg,20,460);
msg="Gender is : "+c1.getSelectedItem();
g.drawString(msg,20,490);
msg="Semester is : "+c2.getSelectedItem();
g.drawString(msg,20,520);
msg="Your branch is : "+lt1.getSelectedItem();
g.drawString(msg,20,550);
msg="Language known to you are : ";
String s2[ ]=lt2.getSelectedItems();
for(int i=0;i<s2.length;i++)
msg+=s2[i]+", ";
g.drawString(msg,20,580);
}
}

You might also like