Tenho um código simples que em um form funciona e em outro o mesmo código não funciona, acredito que deva ser algo no código do form mais implementado, mas não consegui descobrir o que está impedindo de funcionar.
O código é simples, tenho dois radiobuttom, quando marco um, automaticamente o outro é desmarcado.
Alguém pode me ajudar?
Segue o código do form
public class CalcularNota extends javax.swing.JFrame
{
private int posicao = 05;
private List<JTextField> listInput;
private List<ParametroNotaVO> listParametroNota;
/** Creates new form CalcularNota */
public CalcularNota()
{
this.setIcon();
initComponents();
this.getListFundamentos();
}
public void setIcon()
{
URL url = this.getClass().getResource("/imagens/icone/icon_frame_32x32.png");
Image imagemTitulo = Toolkit.getDefaultToolkit().getImage(url);
this.setIconImage(imagemTitulo);
}
private void getListFundamentos()
{
try
{
this.setListParametroNota(this.getParametroNotaDAO().loadAll());
this.setListInput(new ArrayList<>());
for (int i = 0; i < this.getListParametroNota().size(); i++)
{
this.addLabel(this.getListParametroNota().get(i).getNome(), this.getListParametroNota().get(i).getFormula());
}
}
catch (SQLException e)
{
System.out.println(e.getMessage());
}
}
private void addLabel(String nome, String toolTip)
{
JLabel label;
posicao += 40;
label = new JLabel(nome);
label.setVisible(true);
label.setToolTipText(toolTip);
label.setSize(300, 22);
label.setFont(new Font("Times New Roman", Font.BOLD, 18));
label.setForeground(Color.BLACK);
label.setLocation(20, posicao);
this.getContentPane().add(label);
initComponents();
this.addTextField(nome, posicao);
}
private void addTextField(String nome, int posicao)
{
JTextField input;
input = new JTextField();
input.setVisible(true);
//input.setText("Teste");
input.setSize(60, 23);
input.setFont(new Font("Times New Roman", Font.PLAIN, 18));
input.setName("input_" + nome);
input.setLocation(350, posicao);
this.getContentPane().add(input);
initComponents();
this.getListInput().add(input);
}
private boolean validaDados(List<JTextField> list)
{
for (int i = 0; i < list.size(); i++)
{
if (list.get(i).getText().isEmpty())
{
return false;
}
}
return true;
}
private void formulaNota()
{
Double nota;
Double aux;
nota = new Double("0.0");
for (int i = 0; i < this.getListParametroNota().size(); i++)
{
if(this.getListParametroNota().get(i).getNome().equalsIgnoreCase("CAGR LUCRO 5 ANOS"))
{
aux = new Double(buscaTextField(this.getListParametroNota().get(i).getNome()).getText().replaceAll( "," , "." ));
if (aux > 0)
{
nota = nota + this.getListParametroNota().get(i).getPeso();
}
}
if(this.getListParametroNota().get(i).getNome().equalsIgnoreCase("DIVIDENDO - DY"))
{
aux = new Double(buscaTextField(this.getListParametroNota().get(i).getNome()).getText().replaceAll( "," , "." ));
if (aux >= 5)
{
nota = nota + this.getListParametroNota().get(i).getPeso();
}
else
{
if (aux >= 3.65)
{
nota = nota + 0.75;
}
}
}
if(this.getListParametroNota().get(i).getNome().equalsIgnoreCase("DIVIDENDO CONSTANTE"))
{
aux = new Double(buscaTextField(this.getListParametroNota().get(i).getNome()).getText().replaceAll( "," , "." ));
if (aux == 1)
{
nota = nota + this.getListParametroNota().get(i).getPeso();
}
}
if(this.getListParametroNota().get(i).getNome().equalsIgnoreCase("EDIVIDAMENTO"))
{
aux = new Double(buscaTextField(this.getListParametroNota().get(i).getNome()).getText().replaceAll( "," , "." ));
if (aux <= 2)
{
nota = nota + this.getListParametroNota().get(i).getPeso();
}
else
{
if (aux <= 3)
{
nota = nota + 0.75;
}
}
}
if(this.getListParametroNota().get(i).getNome().equalsIgnoreCase("LUCRO ÚLTIMOS 5 ANOS"))
{
aux = new Double(buscaTextField(this.getListParametroNota().get(i).getNome()).getText().replaceAll( "," , "." ));
if (aux == 5)
{
nota = nota + this.getListParametroNota().get(i).getPeso();
}
else
{
if (aux >= 3)
{
nota = nota + 0.75;
}
}
}
if(this.getListParametroNota().get(i).getNome().equalsIgnoreCase("MARGEM LÍQUIDA"))
{
aux = new Double(buscaTextField(this.getListParametroNota().get(i).getNome()).getText().replaceAll( "," , "." ));
if (aux >= 15)
{
nota = nota + this.getListParametroNota().get(i).getPeso();
}
else
{
if (aux >= 10)
{
nota = nota + 0.75;
}
}
}
if(this.getListParametroNota().get(i).getNome().equalsIgnoreCase("ROE"))
{
aux = new Double(buscaTextField(this.getListParametroNota().get(i).getNome()).getText().replaceAll( "," , "." ));
if (aux >= 15)
{
nota = nota + this.getListParametroNota().get(i).getPeso();
}
else
{
if (aux >= 10)
{
nota = nota + 0.75;
}
}
}
if(this.getListParametroNota().get(i).getNome().equalsIgnoreCase("VALOR DE MERCADO"))
{
aux = new Double(buscaTextField(this.getListParametroNota().get(i).getNome()).getText().replaceAll( "," , "." ));
if (aux >= 6)
{
nota = nota + this.getListParametroNota().get(i).getPeso();
}
}
}
this.getInput_nota().setText(nota.toString());
}
private JTextField buscaTextField(String busca)
{
for (int i = 0; i < this.getListInput().size(); i++)
{
if(this.getListInput().get(i).getName().equalsIgnoreCase("input_" + busca))
{
return this.getListInput().get(i);
}
}
return new JTextField();
}
private void salvar()
{
}
private void calcularNota(java.awt.event.ActionEvent evt)
{
// TODO add your handling code here:
if (this.validaDados(this.getListInput()))
{
this.formulaNota();
}
else
{
JOptionPane.showMessageDialog(null, "É necessário preencher todos os campos", "Calcula Nota v1", JOptionPane.INFORMATION_MESSAGE);
}
}
private void seleciona2T(java.awt.event.MouseEvent evt)
{
// TODO add your handling code here:
this.getRadio1T().setSelected(false);
}
private void seleciona1T(java.awt.event.MouseEvent evt)
{
// TODO add your handling code here:
this.getRadio2T().setSelected(false);
}
Esse código do método seleciona1T e seleciona2T não funciona aqui, o mesmo código funciona em qualquer outro form que crio para testar