I have GUI screen which lets you set the privacy of a Contact from a selection being made through RadioButton
. Although I can add the selection to the database like this...
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);
}
I am stuck on retrieving the previously selected item for edit mode. Each radiobutton option belong to a buttongroup.
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
}
in the above method I would like to set the selected item of the radio button. Just as you would do getSelectedItem() for JComboBox, I am trying to achieve the same for radio button. note cDTO
contains the data string, cDTO.getStatus which gets the value from database. But how do I set it to the 3 radio buttons that i have, named allButton
bioButton
noneButton