I'm a student and right now I have a project for my college. this is short of my code.
private void buttonProccesActionPerformed(java.awt.event.ActionEvent evt) {
String gender = String.valueOf(buttongroupGender.getSelection());
//the problem is right over top of this comment
String date = String.valueOf(comboboxDate.getSelectedItem());
String month = String.valueOf(comboboxMonth.getSelectedItem());
String year = String.valueOf(comboboxYear.getSelectedItem());
textareaWrite.setText("");
textareaWrite.append("\nName : " + textfieldName.getText());
textareaWrite.append("\n" + gender);
textareaWrite.append("\nBirth : " + date);
textareaWrite.append(" - " + month);
textareaWrite.append(" - " + year);
textareaWrite.append("\nBirth place : " + textfieldBirthPlace.getText());
}
Everything, every code is working perfectly except the button group.
String gender = String.valueOf(buttongroupGender.getSelection());
I can't get the value of radio button that is selected in button group that has the value of Boy and Girl. Is there any solution for this ?
To solve your problem you have to add
setActionCommand
to all theJRadioButton
during their creation.Example:
I assume that you have already created two
JRadioButton
namelyboy
andgirl
in the constructor part. There you also have to include two more lines each after theJRadioButton
as below:Now, in your
buttonProccesActionPerformed()
method (the code which you have provided), do the following edit: