My assignment is as follows: Create aJApplet that contains twoJTextFields, aJButton, and threeJLabels. When the user types an employee’ s first and last names (separated by a space) in a JTextField, the employee ’ s job title is displayed in a secondJTextField. Include two JLabels to describe theJTextFields used for data entry, and include a third JLabel that holds the employee ’ s title or an error message if no match is found for the employee. Use parallel arrays to store the employees ’ names and job titles. Save the file as JEmployeeTitle.java
I have having an issue specifically with the output of this code, everything compiles correctly, and the only issue I seem to be having is with the output of the name and title in line 81, I believe it is. Any help is appreciated.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JEmployeeTitle extends JApplet implements ActionListener
{
//initialize arrays
String[] Names = {"Maxwell Rudolph", "David Morand", "Andrew Turner", "Andrew Lacquiere", "Joseph Go",
"Ron Kallam", "Tracy Kallam", "Kaylee Morand", "Cindy Morand", "Tim Morand"};
String[] Title = {"Customer Solutions Supervisor", "Customer Service Associate", "Customer Service Associate",
"Technical Support Associate", "Technical Support Associate", "QA Supervisor", "VP of Operations", "Daughter",
"Teacher", "Program Analyst"};
//create labels
JLabel fullNameLabel = new JLabel("Please enter your first and last name separated by a space");
JLabel nameDescription = new JLabel("Your Name");
JLabel jobTitleLabel = new JLabel("");
//set font
Font mainFont = new Font("Times New Roman", Font.PLAIN, 14);
//create text fields
JTextField fullNameText = new JTextField(25);
JTextField jobTitleText = new JTextField(15);
//create button
JButton findTitle = new JButton("Find the title");
//set container
Container con = getContentPane();
@Override
public void init()
{
//set parameters for pulling from the array
final int numberOfItems = 10;
String arrayNum = "";
boolean validItem;
//for loop to run the array pull
for (int x = 0; x < numberOfItems; ++x)
{
if (arrayNum.equals(Names[x]))
{
validItem = true;
jobTitleLabel.setText(Title[x]);
}
else
{
jobTitleLabel.setText("Person is not found.");
}
}
//set fonts for labels
fullNameLabel.setFont(mainFont);
nameDescription.setFont(mainFont);
jobTitleLabel.setFont(mainFont);
//add labels to the container
con.add(fullNameLabel);
con.add(fullNameText);
con.add(jobTitleText);
con.add(findTitle);
//set the layout for the container
con.setLayout(new FlowLayout());
//event handling
findTitle.addActionListener(this);
fullNameText.addActionListener(this);
jobTitleText.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e)
{
//set action to be taken upon button click
String name = fullNameText.getText();
//set the text for the job title label
jobTitleText.setText("The job title of " + Names + "is " + Title);
//add the label for the job title
con.add(jobTitleLabel);
validate();
}
}
The output I am receiving looks like this: The job title of [Ljava.lang.String;@defa1ais [Ljava.lang.String;@f5da06