Re: Help with Simple If else Statement
I have actually modified the code to include a seperate for loop but
it still does the same thing. what am I missing?
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class JEmployeeTitle2 extends JApplet implements
ActionListener
{
JTextField nameentry = new JTextField(10);
JTextField jobtitledisplay = new JTextField(10);
JButton button = new JButton("Search");
JLabel nametitle = new JLabel("Employee First and Last Name");
JLabel titletitle = new JLabel("Employee Job Title");
JLabel result = new JLabel("");
String empnames[] = {"Robert McDougal" , "Christy McDougal",
"Tyler Smith"};
String emptitles[] = {"Computer Technician", "Office Manager",
"Superman"};
public void init()
{
Container con = getContentPane();
con.setLayout(new FlowLayout());
con.add(nametitle);
con.add(nameentry);
con.add(titletitle);
con.add(jobtitledisplay);
con.add(button);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if (source == button) {
for(int i = 0; i < empnames.length; ++i) {
if (empnames[i].equalsIgnoreCase(nameentry.getText()))
{
result.setText(emptitles[i]);
jobtitledisplay.setText(result.getText());
break;
}
else {
for(int b = 0; i < emptitles.length; ++b) {
if
(emptitles[b].equalsIgnoreCase(jobtitledisplay.getText())) {
result.setText(empnames[b]);
nameentry.setText(result.getText());
break;
}
else {
result.setText("No Match Found");
jobtitledisplay.setText(result.getText());
}
}
}
}
}
}
}