Java
Slip24
Q.1) Write a Java Program to accept the details of Employee(Eno, EName,Sal) from the user and display it on the next Frame. (Use AWT) [Marks 30]
Solution
emp.java
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class emp extends Frame implements ActionListener
{
Label l1,l2,l3,l4,l5,l6;
TextField txt1,txt2,txt3,txt4,txt5,txt6;
Button next,cancel;
Panel p1,p2,p3;
Label ll;
emp()
{
ll=new Label("EMPLOYEE INFORMTION");
l1=new Label("Emp No. : -");
l2=new Label("Name : -");
l3=new Label("Salary : -");
txt1=new TextField(20);
txt2=new TextField(20);
txt3=new TextField(20);
next=new Button("NEXT"); next.addActionListener(this);
cancel=new Button("CANCEL"); cancel.addActionListener(this);
p1=new Panel();
p1.setLayout(new GridLayout(3,2));
p1.add(l1);
p1.add(txt1);
p1.add(l2);
p1.add(txt2);
p1.add(l3);
p1.add(txt3);
p2=new Panel();
p2.setLayout(new GridLayout(1,2));
p2.add(next);
p2.add(cancel);
p3=new Panel();
p3.add(ll);
//Panel Arrangment
add(p3,BorderLayout.NORTH);
add(p1,BorderLayout.CENTER);
add(p2,BorderLayout.SOUTH);
setVisible(true);
setSize(300,300);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==next)
{
new empdet(txt1.getText(),txt2.getText(),txt3.getText());
}
if(ae.getSource()==cancel)
{
System.exit(0);
}
}
public static void main(String args[])
{
new emp().show();
}
}
empdet.java
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class empdet extends Frame implements ActionListener
{
Label l1,l2,l3;
Label lt1,lt2,lt3;
Button cancel;
Panel p1=new Panel();
Panel p2=new Panel();
Panel p3=new Panel();
Label ll;
empdet(String b,String c,String d)
{
ll=new Label("EMPLOYEE INFORMTION");
l1=new Label("Emp No. : -");
l2=new Label("Name : -");
l3 = new Label("Salary : -");
lt1=new Label(b);
lt2=new Label(c);
lt3=new Label(d);
cancel=new Button("CLOSE"); cancel.addActionListener(this);
p1.setLayout(new GridLayout(3,2));
p1.add(l1);
p1.add(lt1);
p1.add(l2);
p1.add(lt2);
p1.add(l3);
p1.add(lt3);
p2.setLayout(new GridLayout(1,1));
p2.add(cancel);
p3.add(ll);
add(p3,BorderLayout.NORTH);
add(p1,BorderLayout.CENTER);
add(p2,BorderLayout.SOUTH);
setVisible(true);
setSize(400,400);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==cancel)
{
System.exit(0);
}
}
}
Tags:
java