How to take value from a Radiobuton to save in a Class

Asked

Viewed 19 times

0

I need to make a screen where the client has several options of radio Buttons to select, then I have to take these values and set in a class that has the field valor.

private String nota; /*quero salvar aqui*/

public String getNota() {
   return nota;
}

public void setNota(String nota){
    this.nota = nota;
}


private JRadioButton getRdbtnOtimo() {
        if (rdbtnOtimo == null) {
            rdbtnOtimo = new JRadioButton("\u00D3timo");
            rdbtnOtimo.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    if (rdbtnOtimo.isSelected()) {
                        rdbtnPessimo.setSelected(false);
                        rdbtnNormal.setSelected(false);
                        rdbtnBom.setSelected(false);
                        rdbtnRuim.setSelected(false);
                        ChatMessage cm = new ChatMessage();
                        cm.setNota("Ótimo");
                    }
                }
            });
            rdbtnOtimo.setBackground(new Color(248, 252, 255));
        }
        return rdbtnOtimo;
    }

1 answer

0

Your note string already has the value of the setNota method, what would be the problem? To redeem what you have in the note variable you can try using it like this:

// Exemplo:    
String notaNova = cm.getNota();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.