ola, procuro ajuda para utilizar o radioButton com o banco de dados MySQL no NetBeans. Preciso pegar a seleção do radiobutton armazenar no BD e depois exibila quando solicitado.
segue o q já fiz… até chegar nesse entrave.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package visao;
import controle.Paciente;
import javax.swing.JOptionPane;
/**
*
* @author DiegoLima
*/
public class Interface_Clinica extends javax.swing.JFrame {
Paciente p = new Paciente();
Paciente novo_paciente;
Paciente busca_paciente;
int acao;
/**
* Creates new form Interface_Clinica
*/
public Interface_Clinica() {
initComponents();
}
public void lTF(){
TFCodigo.setText(null);
TFNome.setText(null);
TFIdade.setText(null);
buttonGroup1.clearSelection();
}
public void hTF(boolean estate){
TFCodigo.setEnabled(estate);
TFNome.setEnabled(estate);
TFIdade.setEnabled(estate);
RBFeminino.setEnabled(estate);
RBMasculino.setEnabled(estate);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
TFCodigoBusca = new javax.swing.JTextField();
BTBuscar = new javax.swing.JButton();
jPanel3 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
TFNome = new javax.swing.JTextField();
TFIdade = new javax.swing.JTextField();
BTNovo = new javax.swing.JButton();
BTSalvar = new javax.swing.JButton();
BTExcluir = new javax.swing.JButton();
TFCodigo = new javax.swing.JTextField();
jPanel4 = new javax.swing.JPanel();
RBFeminino = new javax.swing.JRadioButton();
RBMasculino = new javax.swing.JRadioButton();
BTSair = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Clínica Mais Saúde - Cadastro de Pacientes");
jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jLabel1.setText("Código:");
BTBuscar.setText("Buscar");
BTBuscar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BTBuscarActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(16, 16, 16)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(TFCodigoBusca, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(BTBuscar)
.addGap(59, 59, 59))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(TFCodigoBusca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(BTBuscar)
.addComponent(jLabel1))
.addContainerGap(25, Short.MAX_VALUE))
);
jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jLabel2.setText("Código:");
jLabel3.setText("Nome:");
jLabel4.setText("Idade:");
TFNome.setEnabled(false);
TFIdade.setEnabled(false);
BTNovo.setText("Novo");
BTNovo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BTNovoActionPerformed(evt);
}
});
BTSalvar.setText("Salvar");
BTSalvar.setEnabled(false);
BTSalvar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BTSalvarActionPerformed(evt);
}
});
BTExcluir.setText("Excluir");
BTExcluir.setEnabled(false);
BTExcluir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BTExcluirActionPerformed(evt);
}
});
TFCodigo.setEnabled(false);
jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Sexo"));
buttonGroup1.add(RBFeminino);
RBFeminino.setText("Feminino");
RBFeminino.setEnabled(false);
buttonGroup1.add(RBMasculino);
RBMasculino.setText("Masculino");
RBMasculino.setEnabled(false);
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(RBFeminino)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
.addComponent(RBMasculino)
.addGap(30, 30, 30))
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(RBFeminino)
.addComponent(RBMasculino))
.addContainerGap(19, Short.MAX_VALUE))
);
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addGap(21, 21, 21)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(TFCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(jPanel3Layout.createSequentialGroup()
.addGap(23, 23, 23)
.addComponent(BTNovo)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(BTSalvar)
.addGap(108, 108, 108)))
.addComponent(BTExcluir))
.addGroup(jPanel3Layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(TFNome, javax.swing.GroupLayout.PREFERRED_SIZE, 364, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel3Layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(TFIdade, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGap(30, 30, 30)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(TFCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(TFNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(TFIdade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(BTExcluir)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(BTSalvar)
.addComponent(BTNovo)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
BTSair.setText("Sair");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(BTSair)
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(BTSair)
.addGap(171, 171, 171))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 369, javax.swing.GroupLayout.PREFERRED_SIZE)
);
pack();
setLocationRelativeTo(null);
}// </editor-fold>
private void BTBuscarActionPerformed(java.awt.event.ActionEvent evt) {
int codigoBusca;
lTF();
if(TFCodigoBusca.getText().isEmpty()){
JOptionPane.showMessageDialog(null, "O código deve ser Informado!");
}else{
codigoBusca=Integer.parseInt(TFCodigoBusca.getText());
busca_paciente=p.buscar(codigoBusca);
if(busca_paciente == null){
JOptionPane.showMessageDialog(null, "Paciente não encontrado!");
hTF(false);
BTExcluir.setEnabled(false);
BTSalvar.setEnabled(false);
TFCodigoBusca.setText(null);
}else{
JOptionPane.showMessageDialog(null, "Paciente encontrado!");
TFCodigoBusca.setText(null);
TFCodigoBusca.setEnabled(false);
BTExcluir.setEnabled(true);
BTSalvar.setEnabled(true);
TFCodigo.setText(String.valueOf(p.getCodigo()));
TFNome.setText(p.getNome());
TFIdade.setText(String.valueOf(p.getIdade()));
acao = 2;
}
}
}
private void BTExcluirActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void BTNovoActionPerformed(java.awt.event.ActionEvent evt) {
lTF();
hTF(true);
BTSalvar.setEnabled(true);
BTExcluir.setEnabled(false);
TFCodigoBusca.setText(null);
TFCodigoBusca.setEnabled(false);
acao=1;
}
private void BTSalvarActionPerformed(java.awt.event.ActionEvent evt) {
if(TFCodigo.getText().isEmpty() || TFNome.getText().isEmpty()){
JOptionPane.showMessageDialog(null, "As informações deve ser informados!");
}else{
switch(acao){
case 1:{
busca_paciente=p.buscar(Integer.parseInt(TFCodigoBusca.getText()));
if(busca_paciente == null){
p.setCodigo(Integer.parseInt(TFCodigo.getText()));
p.setNome(TFNome.getText());
p.setIdade(Integer.parseInt(TFIdade.getText()));
p.setSexo(buttonGroup1.getSelection());
}
break;
}
case 2:{
break;
}
}
}
}