[英]How can i add items to java text file through GUI combo box(netbeans)
I have already defined the items in the combo box inside gui. 我已经在gui的组合框中定义了项目。 What happens is that im trying to add an entry to the program text file and it says: incompatible types int cannot be converted to string. 发生的情况是,我试图在程序文本文件中添加一个条目,它说:不兼容的类型int无法转换为字符串。 I am having problems with setLocation
and setSkills
. 我在setLocation
和setSkills
方面遇到问题。
private void buttonAddActionPerformed(java.awt.event.ActionEvent evt)
{
Resort p = new Resort();
p.setName(nameTextField.getText().replaceAll("[^a-z.]", ""));
p.setLocation(comboResortLocation.getSelectedIndex());
p.setSkillsByIndex(comboResortSkill.getSelectedIndex());
txtfile.addResort(p);
AddedConfirm confirmed = new AddedConfirm();
confirmed.setVisible(true);
this.setVisible(false);
}
And the part of the code from the other file. 以及部分代码来自另一个文件。
public void setSkillsByIndex (String skills)
{
this.skills = skills;
}
Got it fixed already. 已经解决了。 I just had to change them to Strings and use getSelectedItem instead: 我只需要将它们更改为Strings,而是使用getSelectedItem:
p.setLocationByIndex((String) comboResortLocation.getSelectedItem());
p.setSkillsByIndex((String) comboResortSkill.getSelectedItem());
and the other file: 和另一个文件:
public void setLocationByIndex (String location) { this.location = location; public void setLocationByIndex(字符串位置){this.location = location;
}
public void setSkillsByIndex (String skills) { this.skills = skills; public void setSkillsByIndex(字符串技能){this.skills =技能;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.