Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need in Java for when you click the add button it displays infomormation from te

ID: 3820769 • Letter: N

Question

Need in Java for when you click the add button it displays infomormation from text field.

package HR;

import java.awt.TextComponent;

import java.awt.TextField;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JTextField;

public class Faculty implements ActionListener {

   private String coursetaught;

   private String department;

   private String title;

   private String position_outside_of_university;

   JButton btncoursetaught = new JButton ("course Taught");

   JButton btndepartment = new JButton ("Department");

   JButton btntitle =new JButton ("Title");

   JButton btnposition_outside_of_university =new JButton ("Position");

   JTextField tbcoursetaught =new JTextField("Course Taught");

   JTextField tbdepartment = new JTextField("Department");

   JTextField tbtitle= new JTextField("Title");

   JTextField tbposition_outside_of_university= new JTextField("Position outside of University");

  

public Faculty(String coursetaught, String department, String title, String position_outside_of_univeristy)

   {

   this.coursetaught = coursetaught;

   this.department = department;

   this.title = title;

   this.position_outside_of_university = position_outside_of_university;

  

      

   }

public Faculty()

{

  

   gatherFacultyInfo();

}

public String getcoursetaught()

{

   return coursetaught;

}

public void gatherFacultyInfo() {

  

  

}

public void FacultyPrintMenu() {

  

   HR.pnlGetinfo.add(tbcoursetaught);

   HR.pnlGetinfo.add(tbdepartment);

   HR.pnlGetinfo.add(tbtitle);

   HR.pnlGetinfo.add(tbposition_outside_of_university);

}

@Override

public void actionPerformed(ActionEvent e) {

   System.out.println("Course Taught" + coursetaught);

}

}

Explanation / Answer

Java program:

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

public class Faculty implements ActionListener {
private String coursetaught;
private String department;
private String title;
private String position_outside_of_university;


JButton btncoursetaught = new JButton ("course Taught");
JButton btndepartment = new JButton ("Department");
JButton btntitle =new JButton ("Title");
JButton btnposition_outside_of_university =new JButton ("Position");

JTextField tbcoursetaught =new JTextField("Course Taught");
JTextField tbdepartment = new JTextField("Department");
JTextField tbtitle= new JTextField("Title");
JTextField tbposition_outside_of_university= new JTextField("Position outside of University");

public Faculty(String coursetaught, String department, String title, String position_outside_of_univeristy)
{
this.coursetaught = coursetaught;
this.department = department;
this.title = title;
this.position_outside_of_university = position_outside_of_university;
createFrame();
}
public Faculty()
{
createFrame();
}
public String getcoursetaught()
{
return coursetaught;
}
public void createFrame() {
// Create a JFrame
JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 600);

JPanel buttonPane = new JPanel();
buttonPane.add(tbcoursetaught);
buttonPane.add(tbdepartment);
buttonPane.add(tbtitle);
buttonPane.add(tbposition_outside_of_university);
  
// Add action listener
btncoursetaught.addActionListener(this);
btndepartment.addActionListener(this);
btntitle.addActionListener(this);
btnposition_outside_of_university.addActionListener(this);
  
// Add buttons to JPanel
buttonPane.add(btncoursetaught);
buttonPane.add(btndepartment);
buttonPane.add(btntitle);
buttonPane.add(btnposition_outside_of_university);
}


@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btncoursetaught) {
coursetaught = tbcoursetaught.getText().toString(); // Code to get data from JTextField and update the attributes
} else if (e.getSource() == btndepartment) {
department = tbdepartment.getText().toString();
}else if (e.getSource() == btntitle) {
title = tbtitle.getText().toString();
}else if (e.getSource() == btnposition_outside_of_university) {
position_outside_of_university = tbposition_outside_of_university.getText().toString();
}
  
System.out.println("Course Taught" + coursetaught);
System.out.println("Course Taught" + department);
System.out.println("Course Taught" + title);
System.out.println("Course Taught" + position_outside_of_university);
}

}

Main class:

public class Test{

public static void main(String []args){
System.out.println("Hello World");
new Faculty();
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote