DATE: NAME:SHWETA DARSHINI P
REGNO:412521104139.
EX 8. Java program to create student report using applet, read the
input using text boxes and display the output using buttons
Aim:
To write a program to create student report using applet, read the input using
textbox and display the output using buttons.
Algorithm:
Step1: Start
Step2: Install jdk* and applet won’t support from jdk9 and upper versions.
Step3: Now create a student info class and declare all the required labels,
textboxes and buttons.
Step4: Create init function and create the labels, text fields and buttons
declared in the above class.
Step5: Create the action performed for each text box, Label and button in try
and catch blocks to avoid exceptions.
Step6: Stop.
Program:
import [Link].*;
import [Link].*;
import [Link].*;
public class classstudentreport extends Applet implements ActionListener{
Label
lblTitle,lblRegNo,lblName,lblJava,lblSE,lblCA,lblBI,lblSSPD;
TextField
txtRegNo,txtName,txtJava,txtSE,txtCA,txtBI,txtSSPD;
Button
cmdReport;
int total;
float avg;
public void init(){
setLayout(null);
lblTitle = new Label("Enter Student's Details");
lblRegNo = new Label("[Link] : ");
DATE: NAME:SHWETA DARSHINI P
REGNO:412521104139.
lblName = new Label("Name : ");
lblJava = new Label("Java : ");
lblSE = new Label("SE : ");
lblCA = new Label("CA :");
lblBI = new Label("BI :");
lblSSPD = new Label("SSPD :");
txtRegNo = new TextField(10);
txtName = new TextField(25);
txtJava = new TextField(3);
txtSE = new TextField(3);
txtCA = new TextField(3);
txtBI = new TextField(3);
txtSSPD = new TextField(3);
cmdReport = new Button("View Student Result");
[Link](100,0,200,20);
[Link](0,50,100,20);
[Link](120,50,100,20);
[Link](0,70,100,20);
[Link](120,75,250,20);
[Link](0,100,100,20);
[Link](120,100,40,20);
[Link](0,125,100,20);
[Link](120,125,40,20);
[Link](0,150,100,20);
[Link](120,150,40,20);
[Link](0,175,100,20);
[Link](120,175,40,20);
[Link](0,200,100,20);
[Link](120,200,40,20);
[Link](100,225,150,30);
add(lblTitle);
add(lblRegNo);
add(txtRegNo);
add(lblName);
add(txtName);
add(lblJava);
add(txtJava);
DATE: NAME:SHWETA DARSHINI P
REGNO:412521104139.
add(lblSE);
add(txtSE);
add(lblCA);
add(txtCA);
add(lblBI);
add(txtBI);
add(lblSSPD);
add(txtSSPD);
add(cmdReport);
[Link](this);
}
public void actionPerformed(ActionEvent ae){
try{
int java = [Link]([Link]());
int se = [Link]([Link]());
int ca = [Link]([Link]());
int bi = [Link]([Link]());
int sspd = [Link]([Link]());
total = (java + se + ca + bi + sspd);
avg = total/5;
}
catch(NumberFormatException e){
}
repaint();
}
public void paint(Graphics g){
[Link](" STUDENTREPORT ",100,275);
[Link]("Reg. No = "+[Link](),0,300);
[Link]("Name = "+[Link](),0,325);
[Link]("Java = "+[Link](),0,350);
[Link]("Software Engineering = "+[Link](),0,375);
[Link]("Computer Architecture = "+[Link](),0,400);
[Link]("Banking & Insurance = "+[Link](),0,425);
[Link]("SSPD = "+[Link](),0,450);
[Link]("Total = "+total,0,475);
[Link]("Average = "+avg,0,500);
}
DATE: NAME:SHWETA DARSHINI P
REGNO:412521104139.
}
/*<applet code="classstudentreport" height=800 width=800>
</applet>*/
DATE: NAME:SHWETA DARSHINI P
REGNO:412521104139.
Output:
Result:
Thus, the java program to write a program to write a program to create student
report using applet, read the input using text boxes and display the output
using buttons is executed successfully and output is verified.
DATE: NAME:SHWETA DARSHINI P
REGNO:412521104139.
EX 10: Java program to Implement Thread, Applets Graphics
Animate Ball Movement
Aim:
To write a program to implement thread, applets and graphics to animate ball
movement.
Algorithm:
Step1: Start
Step2: Import the Necessary packages.
Step3: Set the Backgroundcolor (setBackground method) and the color of the
ball (paint method) using methods.
Step4: Create thread and start running it( declare flag variable as true).
Step5: Using the dimensions from the html code, set boundaries within which
the ball can move at a certain rate.
Step6: Repaint the scenario at every instance when while loop gets iterated
every time.
Program:
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public class movingball extends Applet implements Runnable
{
int x,y,dx,dy;
Thread t;
boolean flag;
public void init()
{
setBackground([Link]);
x=100;
y=10;
dx=10;dy=10;
}
DATE: NAME:SHWETA DARSHINI P
REGNO:412521104139.
public void start()
{
flag = true;
t = new Thread(this);
[Link]();
}
public void paint(Graphics g)
{
[Link]([Link]);
[Link](x,y,50,50);
}
public void run()
{
while(flag)
{
Rectangle r = getBounds();
if((x+dx<=0)||(x+dx>=[Link]))
{
dx=-dx;
}
if((y+dy<=0)||(y+dy>=[Link]))
dy=-dy;
x+=dx;
y+=dy;
repaint();
try{
[Link](300);
}
catch(InterruptedException e){}
}
}
public void stop()
{
t = null;
flag = false;
}
}
DATE: NAME:SHWETA DARSHINI P
REGNO:412521104139.
/*
<applet code = "[Link]" height=100 width = 700></applet>
*/
Output:
Result:
Thus a program to implement thread, applets and graphics to animate ball
movement has been successfully executed.