7) Write a Java Program to accept the details of Employee from the user and display it on the next Frame. (Use AWT) Emp.java


import javax.swing.*;
import java.awt.*;
public class Emp extends JFrame
{
JButton jButton1;
JTextField jTextField1;
JTextField jTextField2;
JTextField jTextField3;
JTextField jTextField4;
JTextField jTextField5;

public Emp()
{
JLabel jLabel1 = new JLabel(” Enter Employee Information “);
jTextField1 = new JTextField(10);
jButton1 = new JButton();
JLabel jLabel2 = new JLabel(” Enter Name “);
jTextField2 = new JTextField(10);
JLabel jLabel3 = new JLabel(“Enter Department”);
jTextField3 = new JTextField(10);
JLabel jLabel4 = new JLabel(“Enter Address “);
JLabel jLabel5 = new JLabel(“Enter Salary “);
jTextField4 = new JTextField(10);
JLabel jLabel6 = new JLabel(“Phone No. “);
jTextField5 = new JTextField(10);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
jButton1.setText(“Display”);
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

Container contentPane = getContentPane();
JPanel p=new JPanel();
p.add(jLabel1);
p.add(jLabel2);
p.add(jTextField1);
p.add(jLabel3);
p.add(jTextField2);
p.add(jLabel4);
p.add(jTextField3);
p.add(jLabel5);
p.add(jTextField4);
p.add(jLabel6);
p.add(jTextField5);
p.add(jButton1);
contentPane.add(p);
}

void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
String name1=jTextField1.getText();
String dept=jTextField2.getText();
String addr=jTextField3.getText();
int salr=Integer.parseInt(jTextField4.getText());
int phon=Integer.parseInt(jTextField5.getText());

EmpDisply calfr=new EmpDisply(name1,dept,addr,salr,phon);
calfr.setVisible(true);
dispose();
}

public static void main(String args[])
{
Emp emp= new Emp();
emp.setVisible(true);
emp.setSize(280,220);
emp.setTitle(“Emplyee Details”);
emp.setResizable(false);
}
}

EmpDisply.java

import javax.swing.*;
import java.awt.*;
public class EmpDisply extends JFrame
{
public EmpDisply(String name1,String dept,String addr , int salr,long phon)
{
setVisible(true);
setSize(250,220);
setTitle(“Emplyee Details”);
setResizable(false);

JLabel jLabel1 = new JLabel(” Employee Details “);
JLabel jLabel2 = new JLabel(” Name :- “);
JTextField jTextField1 = new JTextField(10);
JLabel jLabel3 = new JLabel(“Department :- “);
JTextField jTextField2 = new JTextField(10);
JLabel jLabel4 = new JLabel(” Address :- “);
JTextField jTextField3 = new JTextField(10);
JLabel jLabel5 = new JLabel(” Salary :- ” );
JTextField jTextField4 = new JTextField(10);
JLabel jLabel6 = new JLabel(“Phone No :- “);
JTextField jTextField5 = new JTextField(10);

setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

jLabel1.setForeground(new java.awt.Color(255, 51, 255));
jTextField1.setEditable(false);
jTextField2.setEditable(false);
jTextField3.setEditable(false);
jTextField4.setEditable(false);
jTextField5.setEditable(false);
Container contentPane = getContentPane();
JPanel p=new JPanel();
p.add(jLabel1);
p.add(jLabel2);
p.add(jTextField1);
p.add(jLabel3);
p.add(jTextField2);
p.add(jLabel4);
p.add(jTextField3);
p.add(jLabel5);
p.add(jTextField4);
p.add(jLabel6);
p.add(jTextField5);
contentPane.add(p);
jTextField1.setText(name1);
jTextField2.setText(dept);
jTextField3.setText(addr);
jTextField4.setText(“”+salr);
jTextField5.setText(“”+phon);
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s