在我的驱动程序中,它给我找不到符号错误:
“java:201:错误:无法找到符号report.setText(list1.searchR(in));”
“java:257:错误:找不到符号list5.addJob(n2.getText(),”“+(rand5 ++),t,0);”
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MenuDemo extends JFrame implements ActionListener{
indList list1= new indList();
indList list3= new indList();
indList list4= new indList();
indList list5= new indList();
indList list6= new indList();
public static int rand=1000;
public static int rand2=1000;
public static int rand3=1000;
public static int rand4=1000;
public static int rand5=1000;
String ty[] = {"SAB", "Aramco","Sabic","JANA","alMuhaidib"};
JComboBox acty1 =new JComboBox(ty);
JMenu me=new JMenu("Employer");
JMenuItem mep= new JMenuItem("Post Needed Jobs");
JMenuItem mex=new JMenuItem("Exit");
JMenu ms=new JMenu("Job Seeker");
JMenuItem msf= new JMenuItem("Find Available Jobs");
JMenuItem msa= new JMenuItem("Assign to a New Job");
JMenuBar bar=new JMenuBar();
//// post jobs
JLabel l1=new JLabel ("Your organization name:", JLabel.CENTER);
JLabel l2=new JLabel ("The job title needed is:", JLabel.CENTER);
JTextField n2 =new JTextField(50);
JButton b1=new JButton("Submit");
JButton b2=new JButton("Cancel");
JPanel empp1=new JPanel(new GridLayout(3,2));
//////////// Assign
JLabel lll4=new JLabel("The job title that you want to request for:", JLabel.CENTER);
JTextField nnn3=new JTextField(50);
JLabel lll5=new JLabel("Your name:", JLabel.CENTER);
JTextField nnn4=new JTextField(30);
JLabel lll6=new JLabel("ID:", JLabel.CENTER);
JTextField nnn5=new JTextField(10);
JLabel lll7=new JLabel("Phone number:", JLabel.CENTER);
JTextField nnn6=new JTextField(10);
JLabel lll8=new JLabel("Email address:", JLabel.CENTER);
JTextField nnn7=new JTextField(50);
JButton bbb3=new JButton("Send Request");
JButton bbb4=new JButton("Cancel");
JPanel sap2=new JPanel(new GridLayout(6,2));
////////////// report
JTextArea report =new JTextArea(15,40);
JPanel panel3= new JPanel(new FlowLayout());
Font font = new Font("Times New Romman", Font.BOLD, 30);
MenuDemo类:
public MenuDemo(){
setLayout(new FlowLayout());
setTitle("Job Program");
setSize(600,600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
empp1.add(l1);
empp1.add(acty1);
empp1.add(l2);
empp1.add(n2);
empp1.add(b1);
b1.addActionListener(this);
empp1.add(b2);
b2.addActionListener(this);
empp1.setVisible(false);
add(empp1);
/////////// result assign
sap2.add(lll4);
sap2.add(nnn3);
sap2.add(lll5);
sap2.add(nnn4);
sap2.add(lll6);
sap2.add(nnn5);
sap2.add(lll7);
sap2.add(nnn6);
sap2.add(lll8);
sap2.add(nnn7);
sap2.add(bbb3);
bbb3.addActionListener(this);
sap2.add(bbb4);
bbb4.addActionListener(this);
sap2.setVisible(false);
add(sap2);
///////// menu
me.add(mep);
me.add(mex);
mep.addActionListener(this);
mex.addActionListener(this);
bar.add(me);
ms.add(msf);
ms.add(msa);
msf.addActionListener(this);
msa.addActionListener(this);
bar.add(ms);
setJMenuBar(bar);
//////////
Font fnt = new Font("Arial", Font.BOLD, 14);
panel3.add(new JLabel ("The Result of search:"));
JScrollPane scrolpane = new JScrollPane(report);
report.setFont(fnt);
scrolpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrolpane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
panel3.add(scrolpane);
panel3.setVisible(false);
add(panel3);
setVisible(true);
}
public static void main(String[] args)
{
MenuDemo jp=new MenuDemo();
}
public void actionPerformed(ActionEvent e)
{
report.setText("");
String c=e.getActionCommand();
if(c.equals("Post Needed Jobs"))
{
empp1.setVisible(true);
panel3.setVisible(false);
sap2.setVisible(false);
}
else if(c.equals("Exit"))
{
JOptionPane.showMessageDialog(null,"Thank You for using Job Program");
System.exit(0);
}
else if(c.equals("Find Available Jobs"))
{
empp1.setVisible(false);
panel3.setVisible(true);
sap2.setVisible(false);
String in= JOptionPane.showInputDialog("Enter Industry To Search in :[SAB, Aramco,Sabic,JANA,alMuhaidib]");
if(in.equalsIgnoreCase("SAB"))
{
report.setText("");
第201行:
report.setText(list1.searchR(in)) ;
}
if(in.equalsIgnoreCase("Aramco"))
{
report.setText("");
report.setText(list2.searchR(in)) ;
}
if(in.equalsIgnoreCase("Sabic"))
{
report.setText("");
report.setText(list3.searchR(in)) ;
}
if(in.equalsIgnoreCase("JANA"))
{
report.setText("");
report.setText(list4.searchR(in)) ;
}
if(in.equalsIgnoreCase("alMuhaidib"))
{
report.setText("");
report.setText(list5.searchR(in)) ;
}
else
JOptionPane.showMessageDialog(null,"Enter correct industry in this list:[SAB, Aramco,Sabic,JANA,alMuhaidib]");
}
else if(c.equals("Submit"))
{
String t= (String)acty1.getSelectedItem();
String in=JOptionPane.showInputDialog("Enter Industry To Add in :[SAB, Aramco,Sabic,JANA,alMuhaidib]");
if(in.equalsIgnoreCase("SAB"))
{
list1.addJob(n2.getText(),""+(rand++) ,t,0);
n2.setText("");
}
else if(in.equalsIgnoreCase("Aramco"))
{
list2.addJob(n2.getText(),""+(rand2++) ,t,0);
}
else if(in.equalsIgnoreCase("Sabic"))
{
list3.addJob(n2.getText(),""+(rand3++) ,t,0);
}
else if(in.equalsIgnoreCase("JANA"))
{
list4.addJob(n2.getText(),""+(rand4++) ,t,0);
}
else if(in.equalsIgnoreCase("alMuhaidib"))
{
第257行:
list5.addJob(n2.getText(),""+(rand5++) ,t,0);
}
else
{
JOptionPane.showMessageDialog(null,"Enter Correct Industry:[SAB, Aramco,Sabic,JANA,alMuhaidib]");
}
}
}
}
IndLisit类:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class indList {
public indNode head, tail;
public indList(){
head=tail=null;
}
public boolean isEmpty(){
return head==null;
}
public void addind(String j, String i)
{
if(head==null)
{
head=tail=new indNode(j);
JOptionPane.showMessageDialog(null,"Industry added");
}
else if (head!=null)
{
// indNode tmp;
// for( tmp=head;tmp!=null && !(tmp.info1.equalsIgnoreCase(i)) ;tmp=tmp.next) ;
// if( tmp== null )
{
tail.next=new indNode(j);
tail=tail.next;
JOptionPane.showMessageDialog(null,"Industry Added");
}
/* else
JOptionPane.showMessageDialog(null,"This job title Have been added Before"); */
}
}
public String printJob()
{
indNode tmp;
if(head==null)
return " The industry List is Empty ";
else
{
String r="";
for( tmp=head;tmp!=null ;tmp=tmp.next)
r+="\n============\n The Industry:"+tmp.info2;
return r;
}
}
public boolean searchind(String j)
{
indNode tmp;
for( tmp=head;tmp!=null && !(tmp.info2.equalsIgnoreCase(j)) ;tmp=tmp.next) ;
//JOptionPane.showMessageDialog(null,"The Account results: "+ tmp != null);
if (tmp == null)
return false;
else
return true;
}
}
答案 0 :(得分:1)
类indList没有searchR或addJob方法。这会导致我认为的编译错误。
public void searchR(String input) {
// do something useful here
}
public void addJob(String input, String id, String selectedItem, int pos) {
// do something useful here
}
我不知道你的代码应该做什么,所以我不能提供上述方法的实现,即使我想这样做。
您的代码存在很多问题,您可以修复它们以使其更具可读性和更好的可维护性:
使用有意义的变量名称。而不是'n2'给出一个描述该字段含义的名称。
类名以大写字符开头。尽量避免不需要的缩写。同时避免引用数据结构,所以'Industries'而不是'indList'和'IndustryNode'而不是'indNode'。
作为对象引用的字段会自动初始化为null,因此您可以替换
public indNode head, tail;
public indList(){
head=tail=null;
}
带
public IndustryNode head;
public IndustryNode tail;
还有更多可能的改进,但这是一个开始。