Answer to Question #243876 in Java | JSP | JSF for junior

Question #243876

Create an employee form that accepts an employee number, employee name, employee surname, employee department, gender, and salary


1
Expert's answer
2021-09-29T01:18:32-0400




import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class MyFrame
        extends JFrame
        implements ActionListener {

    // Components of the Form
    private Container c;
    private JLabel title;
    private JLabel name;
    private JTextField tname;
    private JLabel sur_name;
    private JTextField tsur_name;
    private JLabel department;
    private JTextField tdepartment;
    private JLabel mno;
    private JTextField tmno;
    private JLabel gender;
    private JRadioButton male;
    private JRadioButton female;
    private ButtonGroup gengp;
    private JLabel salary;
    private JTextField tsalary;
    private JCheckBox term;
    private JButton sub;
    private JButton reset;
    private JTextArea tout;
    private JLabel res;
    private JTextArea resadd;


    // constructor, to initialize the components
    // with default values.
    public MyFrame()
    {
        setTitle("Employee Form");
        setBounds(300, 90, 900, 600);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setResizable(false);

        c = getContentPane();
        c.setLayout(null);

        title = new JLabel("Employee Form");
        title.setFont(new Font("Arial", Font.PLAIN, 30));
        title.setSize(300, 30);
        title.setLocation(300, 30);
        c.add(title);

        mno = new JLabel("Number");
        mno.setFont(new Font("Arial", Font.PLAIN, 20));
        mno.setSize(100, 20);
        mno.setLocation(100, 100);
        c.add(mno);

        tmno = new JTextField();
        tmno.setFont(new Font("Arial", Font.PLAIN, 15));
        tmno.setSize(190, 20);
        tmno.setLocation(200, 100);
        c.add(tmno);

        name = new JLabel("Name");
        name.setFont(new Font("Arial", Font.PLAIN, 20));
        name.setSize(190, 20);
        name.setLocation(100, 150);
        c.add(name);

        tname = new JTextField();
        tname.setFont(new Font("Arial", Font.PLAIN, 15));
        tname.setSize(190, 20);
        tname.setLocation(200, 150);
        c.add(tname);

        sur_name = new JLabel("Surname");
        sur_name.setFont(new Font("Arial", Font.PLAIN, 20));
        sur_name.setSize(100, 20);
        sur_name.setLocation(100, 200);
        c.add(sur_name);

        tsur_name = new JTextField();
        tsur_name.setFont(new Font("Arial", Font.PLAIN, 15));
        tsur_name.setSize(190, 20);
        tsur_name.setLocation(200, 200);
        c.add(tsur_name);



        gender = new JLabel("Gender");
        gender.setFont(new Font("Arial", Font.PLAIN, 20));
        gender.setSize(100, 20);
        gender.setLocation(100, 250);
        c.add(gender);

        male = new JRadioButton("Male");
        male.setFont(new Font("Arial", Font.PLAIN, 15));
        male.setSelected(true);
        male.setSize(75, 20);
        male.setLocation(200, 250);
        c.add(male);

        female = new JRadioButton("Female");
        female.setFont(new Font("Arial", Font.PLAIN, 15));
        female.setSelected(false);
        female.setSize(80, 20);
        female.setLocation(275, 250);
        c.add(female);

        gengp = new ButtonGroup();
        gengp.add(male);
        gengp.add(female);


        department = new JLabel("department");
        department.setFont(new Font("Arial", Font.PLAIN, 20));
        department.setSize(190, 20);
        department.setLocation(100, 300);
        c.add(department);

        tdepartment = new JTextField();
        tdepartment.setFont(new Font("Arial", Font.PLAIN, 15));
        tdepartment.setSize(190, 25);
        tdepartment.setLocation(200, 300);
        c.add(tdepartment);

        salary = new JLabel("Salary");
        salary.setFont(new Font("Arial", Font.PLAIN, 20));
        salary.setSize(190, 20);
        salary.setLocation(100, 350);
        c.add(salary);

        tsalary = new JTextField();
        tsalary.setFont(new Font("Arial", Font.PLAIN, 15));
        tsalary.setSize(100, 25);
        tsalary.setLocation(200, 350);
        c.add(tsalary);


        sub = new JButton("Submit");
        sub.setFont(new Font("Arial", Font.PLAIN, 15));
        sub.setSize(100, 20);
        sub.setLocation(150, 400);
        sub.addActionListener(this);
        c.add(sub);



        tout = new JTextArea();
        tout.setFont(new Font("Arial", Font.PLAIN, 15));
        tout.setSize(300, 400);
        tout.setLocation(500, 100);
        tout.setLineWrap(true);
        tout.setEditable(false);
        c.add(tout);

        res = new JLabel("");
        res.setFont(new Font("Arial", Font.PLAIN, 20));
        res.setSize(500, 25);
        res.setLocation(100, 500);
        c.add(res);

        resadd = new JTextArea();
        resadd.setFont(new Font("Arial", Font.PLAIN, 15));
        resadd.setSize(200, 75);
        resadd.setLocation(580, 175);
        resadd.setLineWrap(true);
        c.add(resadd);

        setVisible(true);
    }

    // method actionPerformed()
    // to get the action performed
    // by the user and act accordingly
    public void actionPerformed(ActionEvent e)
    {
        if (e.getSource() == sub) {
                String data1;
                String data
                        = "Employee name: "
                        + tname.getText() + "\n"
                        + "Employee Surname: "
                        + tsur_name.getText() + "\n"
                        + "Employee number : "
                        + tmno.getText() + "\n";
                if (male.isSelected())
                    data1 = "Gender : Male"
                            + "\n";
                else
                    data1 = "Gender : Female"
                            + "\n";

                String data3 = "Employee Department : " + tdepartment.getText() + "\n"
                        + "Employee Salary: "+tsalary.getText() + "\n";
                tout.setText(data + data1 + data3);
                tout.setEditable(false);
                res.setText("Employess data captured Successfully..");

        }


    }
}

public class Main {

    public static void main(String[] args) {
   // write your code here
        MyFrame f = new MyFrame();
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS