簡體   English   中英

如何通過GUI組合框(NetBeans)將項目添加到Java文本文件

[英]How can i add items to java text file through GUI combo box(netbeans)

我已經在gui的組合框中定義了項目。 發生的情況是,我試圖在程序文本文件中添加一個條目,它說:不兼容的類型int無法轉換為字符串。 我在setLocationsetSkills方面遇到問題。

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);
}                                    

以及部分代碼來自另一個文件。

public void setSkillsByIndex (String skills)
{
    this.skills = skills;            
}        

已經解決了。 我只需要將它們更改為Strings,而是使用getSelectedItem:

   p.setLocationByIndex((String) comboResortLocation.getSelectedItem());

   p.setSkillsByIndex((String) comboResortSkill.getSelectedItem());

和另一個文件:

public void setLocationByIndex(字符串位置){this.location = location;

    }        

public void setSkillsByIndex(字符串技能){this.skills =技能;

    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM