Validation of CheckBox and RadioButton [closed]

0

How to validate and return a message if the CheckBox and RadioButton components are not selected in an application? JAVA

    
asked by anonymous 19.04.2018 / 09:22

1 answer

2

In CheckBox and RadioButton there is a method that can be used to do this test, isSelected() that returns true if your component is selected.

In this way you can use it to show your message, you just have to deny this test before.

 if (!seuCheckBox.isSelected()) {
      System.out.println("checkbox não foi selecionado");
      JOptionPane.showMessageDialog(this, "Checkbox não foi Selecionado");
 }

In android this same method is named isChecked

if (!seuCheckBox.isChecked()) {
  Toast.makeText(getActivity(), "checkbox não selecionado",
    Toast.LENGTH_LONG).show();
}
    
19.04.2018 / 16:33