-1
當用戶在JTextField中輸入員工的姓名(用空格分隔)時,員工的職位將顯示在第二個JTextField中。包括 twoJLabels描述用於數據輸入theJTextFields,以及包括第三 JLabel的,如果沒有找到匹配的 員工持有該員工的標題或錯誤消息Swing Java員工計劃
每一件事工作正常,但是當我包括以下組成部分代碼只出現錯誤信息 「員工未找到」 即使陣列matches.Without這一說法代碼工作fine.please help..thanks
if(!(name.equalsIgnoreCase(empName[x]) || job.equalsIgnoreCase(jobName[x])))
{
errorortitle.setText("Employee not found");
}
package appletLesson;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Color.*;
public class JEmployeeTitle extends JApplet implements ActionListener
{
String[] empName = {"James", "Tom", "Steve", "Barack", "John"};
String[] jobName = {"Blunt", "Kites", "Jobs", "Obama", "Smith"};
String[] jobTitle = {"Actor", "Buisness men", "CEO", "President", "Painter"};
JLabel fnameLabel = new JLabel("Enter First Name:");
JLabel lnameLabel = new JLabel("ENter Last Name:");
JButton button = new JButton("Submit");
JLabel errorortitle = new JLabel(" ");
JTextField fnameField = new JTextField(20);
JTextField lnameField = new JTextField(20);
Container con = getContentPane();
public void init()
{
con.setBackground(Color.YELLOW);
con.add(fnameLabel);
con.add(fnameField);
con.add(lnameLabel);
con.add(lnameField);
con.add(button);
con.add(errorortitle);
con.setLayout(new FlowLayout());
fnameField.addActionListener(this);
lnameField.addActionListener(this);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
String name = fnameField.getText();
String job = lnameField.getText();
for(int x = 0; x < 5; x++)
{
if(name.equalsIgnoreCase(empName[x]) || job.equalsIgnoreCase(jobName[x]))
{
errorortitle.setText(jobTitle[x]);
}
if(!(name.equalsIgnoreCase(empName[x]) || job.equalsIgnoreCase(jobName[x])))
{
errorortitle.setText("Employee not found");
}
}
validate();
}
}
我們不做你的功課。什麼是錯誤,你試圖糾正這種情況? – hexafraction
@hexafraction我正在投票結束...... –
你怎麼能告訴這是作業? – chiliNUT