我有 GUI 屏幕,可让您通过选择来设置联系人的隐私RadioButton
。虽然我可以像这样将选择添加到数据库中......
private void addContactButtonActionPerformed(java.awt.event.ActionEvent evt) {
try {
ContactDAO cDao = new ContactDAO();
final ContactDTO cdto = new ContactDTO();
String privacy = "";
String alumni = "";
if (all.isSelected()) {
privacy = all.getText();
}
if (bio.isSelected()) {
privacy = bio.getText();
}
if (none.isSelected()) {
privacy = none.getText();
}
if (yes.isSelected()) {
alumni = yes.getText();
}
if (no.isSelected()) {
alumni = no.getText();
}
cdto.setAlumni(alumni);
cdto.setStatus(privacy);
cDao.add(cdto);
}
我被困在检索先前选择的项目以进行编辑模式。每个单选按钮选项都属于一个按钮组。
private void editContact() {
txtID1.setText(String.valueOf(cDTO.getID()));
txtTitle1.setText(cDTO.getTitle());
txtFn1.setText(cDTO.getForename());
txtSn1.setText(cDTO.getSurname());
//get status from cDTO.getStaus and adjust appropriately to the radio button
}
在上面的方法中我想设置单选按钮的选中项。就像您对 JComboBox 执行 getSelectedItem() 一样,我正在尝试为单选按钮实现相同的效果。notecDTO
包含从数据库中获取值的数据字符串 cDTO.getStatus。但是我如何将它设置为我拥有的 3 个单选按钮,名为allButton
bioButton
noneButton