Slide 1
Slide 2
Slide 3

Radio Button in java programming (V79)

No Comments

JRadio Button With JButton Group

 JRadioButton is represented by the JRadioButton class. To make them mutually exclusive (only one option can be selected at a time), we place them inside a ButtonGroup.

Example:


Source Code:

Copied!
    private void btnShowActionPerformed(java.awt.event.ActionEvent evt) {                                        
        String selected = "";

        if (rbJava.isSelected()) {
            selected = "Java";
        } else if (rbPython.isSelected()) {
            selected = "Python";
        } else if (rbCpp.isSelected()) {
            selected = "C++";
        }

        lblResult.setText("You selected: " + selected);
    }                                                                                   

Result:

Watch the video:

back to top