import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class FocusLis extends Applet implements FocusListener
{
Label l1,l2,l3,l4,l5,l6,l7;
TextField t1,t2,t3,t4,t5,t6,t7;
public void init()
{
l1=new Label("Enter Name");
l2=new Label("Marks 1 ");
l3=new Label("Marks 1 ");
l4=new Label("Marks 1 ");
l5=new Label("Marks 1 ");
l6=new Label("Total ");
l7=new Label("Average ");
t1=new TextField(15);
t2=new TextField(15);
t3=new TextField(15);
t4=new TextField(15);
t5=new TextField(15);
t6=new TextField(15);
t7=new TextField(15);
setBackground(Color.green);
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(l4);
add(t4);
add(l5);
add(t5);
add(l6);
add(t6);
add(l7);
add(t7);
t5.addFocusListener(this);
t1.addFocusListener(this);
}
public void focusGained(FocusEvent fe)
{
if(fe.getSource()==t1)
{
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
t6.setText("");
t7.setText("");
}
}
public void focusLost(FocusEvent fe)
{
if(fe.getSource()==t5)
{
int m1=Integer.parseInt(t2.getText());
int m2=Integer.parseInt(t3.getText());
int m3=Integer.parseInt(t4.getText());
int m4=Integer.parseInt(t5.getText());
int tot=m1+m2+m3+m4;
t6.setText(String.valueOf(tot));
t7.setText(String.valueOf(tot/4.0f));
}
}
}
/*
<applet code=FocusLis height=300 width=250></applet>
*/
import java.applet.*;
import java.awt.event.*;
public class FocusLis extends Applet implements FocusListener
{
Label l1,l2,l3,l4,l5,l6,l7;
TextField t1,t2,t3,t4,t5,t6,t7;
public void init()
{
l1=new Label("Enter Name");
l2=new Label("Marks 1 ");
l3=new Label("Marks 1 ");
l4=new Label("Marks 1 ");
l5=new Label("Marks 1 ");
l6=new Label("Total ");
l7=new Label("Average ");
t1=new TextField(15);
t2=new TextField(15);
t3=new TextField(15);
t4=new TextField(15);
t5=new TextField(15);
t6=new TextField(15);
t7=new TextField(15);
setBackground(Color.green);
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(l4);
add(t4);
add(l5);
add(t5);
add(l6);
add(t6);
add(l7);
add(t7);
t5.addFocusListener(this);
t1.addFocusListener(this);
}
public void focusGained(FocusEvent fe)
{
if(fe.getSource()==t1)
{
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
t6.setText("");
t7.setText("");
}
}
public void focusLost(FocusEvent fe)
{
if(fe.getSource()==t5)
{
int m1=Integer.parseInt(t2.getText());
int m2=Integer.parseInt(t3.getText());
int m3=Integer.parseInt(t4.getText());
int m4=Integer.parseInt(t5.getText());
int tot=m1+m2+m3+m4;
t6.setText(String.valueOf(tot));
t7.setText(String.valueOf(tot/4.0f));
}
}
}
/*
<applet code=FocusLis height=300 width=250></applet>
*/
No comments:
Post a Comment