12) Write a java program to accept the details of employee from the user and display Payment slip on the next Frame. PaySlip.java


 

import javax.swing.*;
import java.awt.*;
public class PaySlip extends JFrame
{
JTextField jTextField1;
JTextField jTextField2;
JTextField jTextField3;
JTextField jTextField4;
public PaySlip()
{
JLabel jLabel1 = new JLabel(” Employee Detail “);
JLabel jLabel2 = new JLabel(“Name:- “);
JLabel jLabel3 = new JLabel(“Basic Salary :-”);
JLabel jLabel4 = new JLabel(“Allowance in %”);
JLabel jLabel5 = new JLabel(“Deduction in %”);
jTextField1 = new JTextField(10);
jTextField2 = new JTextField(10);
jTextField3 = new JTextField(10);
jTextField4 = new JTextField(10);
JButton jButton1 = new JButton();

setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

jButton1.setText(“Calculate”);
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(jButton1);
contentPane.add(p);
}
void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String name1=jTextField1.getText();
int basicsal=Integer.parseInt(jTextField2.getText());
int allow1=Integer.parseInt(jTextField3.getText());
int deduct1=Integer.parseInt(jTextField4.getText());
PaySlip1 calfr=new PaySlip1(name1,basicsal,allow1,deduct1);
calfr.setVisible(true);
}
public static void main(String args[])
{
PaySlip ps= new PaySlip();
ps.setVisible(true);
ps.setSize(230,220);
ps.setTitle(“Emplyee Details”);
ps.setResizable(false);
}
}

PaySlip1.java
import javax.swing.*;
import java.awt.*;
public class PaySlip1 extends javax.swing.JFrame
{

public PaySlip1() { }
public PaySlip1(String name1,int basicsal,int allows1 , int deduct1)
{
JLabel jLabel1 = new JLabel(” Payment Slip “);
JLabel jLabel2 = new JLabel(” Name :- “);
JTextField jTextField1 = new JTextField(10);
JLabel jLabel3 = new JLabel(“basic :-”);
JTextField jTextField2 = new JTextField(10);
JLabel jLabel4 = new JLabel(“Allowance”);
JTextField jTextField3 = new JTextField(10);
JLabel jLabel5 = new JLabel(“Deduction”);
JTextField jTextField4 = new JTextField(10);
JLabel jLabel6 = new JLabel(“Net Salary :-”);
JTextField jTextField5 = new JTextField(10);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
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);
setVisible(true);
setSize(230,220);
setTitle(“Payment Slip”);
setResizable(false);
jTextField1.setText(name1);
jTextField2.setText(“”+basicsal);
int allows2=((basicsal*allows1)/100);
jTextField3.setText(“”+allows2);
int deduct2=((basicsal*deduct1)/100);
jTextField4.setText(“”+deduct2);
jTextField5.setText(“”+(basicsal+allows2-deduct2));
}
}

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