Home > Back-end >  Swing consult how to get the value of the radio button
Swing consult how to get the value of the radio button

Time:11-28

Hope to get the selected button, then can save to the database, how to write?

CodePudding user response:

//radio button to monitor events
RbbtnMan. AddActionListener (new ActionListener () {

@ Override
Public void actionPerformed (an ActionEvent e) {
//TODO Auto - generated method stub
String info="";
Attribute name//by panel access to all of the components on the panel
For (Component c: pane1. GetComponents ()) {
//by instanceof method screening the checkbox component
If (c instanceof JRadioButton) {
//determine whether checkbox component is selected
If (((JRadioButton), c). An isSelected ()) {
//get the check box component information
Info +=((JRadioButton) c) getText ();
}
}
}
System. The out. Println (info);

CodePudding user response:

reference 1st floor usecf response:

//radio button to monitor eventsRbbtnMan. AddActionListener (new ActionListener () {

@ Override
Public void actionPerformed (an ActionEvent e) {
//TODO Auto - generated method stub
String info="";
Attribute name//by panel access to all of the components on the panel
For (Component c: pane1. GetComponents ()) {
//by instanceof method screening the checkbox component
If (c instanceof JRadioButton) {
//determine whether checkbox component is selected
If (((JRadioButton), c). An isSelected ()) {
//get the check box component information
Info +=((JRadioButton) c) getText ();
}
}
}
System. The out. Println (info);

Yesterday has been solved, but thank you very much

CodePudding user response:

To solve the problem and how ah I also encountered the same problem please
  • Related