0% found this document useful (0 votes)
25 views3 pages

Student

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

Student

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

package Pkg1;

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

//<applet code="Student2" width=500 height=500>

public class Student2 extends Applet implements ActionListener{

int m1,m2,m3,m4,m5,sum;
float avg, per;

Label l1 = new Label("Roll No");


Label l2 = new Label("Name");
Label l3 = new Label("English");
Label l4 = new Label("Hindi");
Label l5 = new Label("Physics");
Label l6 = new Label("Chemistry");
Label l7 = new Label("Biology");

TextField t1 = new TextField(19);


TextField t2 = new TextField(19);
TextField t3 = new TextField(19);
TextField t4 = new TextField(19);
TextField t5 = new TextField(19);
TextField t6 = new TextField(19);
TextField t7 = new TextField(19);

Button b1 = new Button("Calculate");


Button b2 = new Button("Clear");
public void init()
{
setLayout(null);
add(l1);
add(t1);
l1.setBounds(30, 30, 70 ,25);
t1.setBounds(100, 30, 150, 25);

add(l2);
add(t2);
l2.setBounds(30, 70, 70 ,20);
t2.setBounds(100, 70, 150, 25);

add(l3);
add(t3);
l3.setBounds(30, 110, 70 ,20);
t3.setBounds(100, 110, 150, 25);

add(l4);
add(t4);
l4.setBounds(30, 150, 70 ,20);
t4.setBounds(100, 150, 150, 25);

add(l5);
add(t5);
l5.setBounds(30, 190, 70 ,20);
t5.setBounds(100, 190, 150, 25);

add(l6);
add(t6);
l6.setBounds(30, 230, 70 ,20);
t6.setBounds(100, 230, 150, 25);

add(l7);
add(t7);
l7.setBounds(30, 270, 70 ,20);
t7.setBounds(100, 270, 150, 25);

add(b1);
b1.setBounds(40, 310, 100, 30);
b1.addActionListener(this);
add(b2);
b2.setBounds(150, 310, 100, 30);
b2.addActionListener(this);
}

public void actionPerformed(ActionEvent e)


{
if(e.getSource()==b1)
{
m1 = Integer.parseInt(t3.getText());
m2 = Integer.parseInt(t4.getText());
m3 = Integer.parseInt(t5.getText());
m4 = Integer.parseInt(t6.getText());
m5 = Integer.parseInt(t7.getText());
sum = m1+m2+m3+m4+m5;
avg = sum/5;
per=(sum*100)/500;
repaint();
}
if(e.getSource()==b2)
{
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
t6.setText("");
t7.setText("");
repaint();
sum = 0;
avg = 0.0f;
per = 0.0f;
}
}

public void paint(Graphics g)


{
g.drawString("Roll No is : "+t1.getText(), 30, 400);
g.drawString("Name is : "+t2.getText(), 30, 440);
g.drawString("Total Marks is : "+sum, 30, 480);
g.drawString("Average is : "+avg, 30, 520);
g.drawString("Percentage is : "+per, 30, 560);
}
}

You might also like