1 回答
TA贡献1785条经验 获得超4个赞
您应该添加一个action listener来jcombobox获取所选值String,然后在另一个类中使用该值,试试这个:
public class BloodList extends JComboBox <String> {
private String s="";
private String[] bloodList =
{
"1",
"2",
"3",
};
public BloodList() {
for (int i=0; i < bloodList.length; i++)
{
this.addItem(bloodList[i]);
};
}
ActionListener cbActionListener = new ActionListener() {//add actionlistner to listen for change
@Override
public void actionPerformed(ActionEvent e) {
s = (String) BloodList.this.getSelectedItem();//get the selected string
}
};
this.addActionListener(cbActionListener);
public String getS(){return s;}
}
现在您可以String通过使用该getS()方法在另一个类中使用它。
添加回答
举报