Segue o c'odigo completo. Pelo visto, eu não coloquei o setActionCommand()
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package gui;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ButtonGroup;
import javax.swing.ButtonModel;
import javax.swing.table.DefaultTableModel;
/**
*
* @author André Ravazzi
*/
public class RoupaUsada extends javax.swing.JDialog {
/**
* Creates new form RoupaUsada
*/
public RoupaUsada(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
}
/**
* 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() {
ocasiaoGroup = new javax.swing.ButtonGroup();
horarioGroup = new javax.swing.ButtonGroup();
tempoGroup = new javax.swing.ButtonGroup();
lookGroup = new javax.swing.ButtonGroup();
jPanel1 = new javax.swing.JPanel();
jTextField1 = new javax.swing.JTextField();
jButtonMostrarRoupas = new javax.swing.JButton();
jLabelOcasiao = new javax.swing.JLabel();
jLabelTempo = new javax.swing.JLabel();
jLabelHorario = new javax.swing.JLabel();
jLabelLook = new javax.swing.JLabel();
jRadioFacul = new javax.swing.JRadioButton();
jRadioPaquera = new javax.swing.JRadioButton();
jRadioFamilia = new javax.swing.JRadioButton();
jRadioAmigos = new javax.swing.JRadioButton();
jRadioDia = new javax.swing.JRadioButton();
jRadioNoite = new javax.swing.JRadioButton();
jRadioFrio = new javax.swing.JRadioButton();
jRadioQuente = new javax.swing.JRadioButton();
jRadioFino = new javax.swing.JRadioButton();
jRadioCasual = new javax.swing.JRadioButton();
jRadioSerio = new javax.swing.JRadioButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jButton2 = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
jLabelOcasiao1 = new javax.swing.JLabel();
jTextIdRoupa = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(248, 69, 69));
jTextField1.setBackground(new java.awt.Color(248, 69, 69));
jTextField1.setFont(new java.awt.Font("Century Gothic", 0, 24)); // NOI18N
jTextField1.setForeground(new java.awt.Color(204, 255, 255));
jTextField1.setText("Roupa que usei hoje");
jTextField1.setBorder(null);
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(262, 262, 262)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 53, Short.MAX_VALUE)
.addContainerGap())
);
jButtonMostrarRoupas.setText("Mostrar Guarda-Roupas");
jButtonMostrarRoupas.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonMostrarRoupasActionPerformed(evt);
}
});
jLabelOcasiao.setFont(new java.awt.Font("Century Gothic", 0, 14)); // NOI18N
jLabelOcasiao.setText("Ocasião");
jLabelTempo.setFont(new java.awt.Font("Century Gothic", 0, 14)); // NOI18N
jLabelTempo.setText("Tempo");
jLabelHorario.setFont(new java.awt.Font("Century Gothic", 0, 14)); // NOI18N
jLabelHorario.setText("Horário");
jLabelLook.setFont(new java.awt.Font("Century Gothic", 0, 14)); // NOI18N
jLabelLook.setText("Look");
ocasiaoGroup.add(jRadioFacul);
jRadioFacul.setFont(new java.awt.Font("Century", 0, 15)); // NOI18N
jRadioFacul.setText("facul");
jRadioFacul.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioFaculActionPerformed(evt);
}
});
ocasiaoGroup.add(jRadioPaquera);
jRadioPaquera.setFont(new java.awt.Font("Century", 0, 15)); // NOI18N
jRadioPaquera.setText("paquera");
jRadioPaquera.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioPaqueraActionPerformed(evt);
}
});
ocasiaoGroup.add(jRadioFamilia);
jRadioFamilia.setFont(new java.awt.Font("Century", 0, 15)); // NOI18N
jRadioFamilia.setText("família");
ocasiaoGroup.add(jRadioAmigos);
jRadioAmigos.setFont(new java.awt.Font("Century", 0, 15)); // NOI18N
jRadioAmigos.setText("amigos");
jRadioAmigos.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioAmigosActionPerformed(evt);
}
});
horarioGroup.add(jRadioDia);
jRadioDia.setFont(new java.awt.Font("Century", 0, 15)); // NOI18N
jRadioDia.setText("dia");
horarioGroup.add(jRadioNoite);
jRadioNoite.setFont(new java.awt.Font("Century", 0, 15)); // NOI18N
jRadioNoite.setText("noite");
jRadioNoite.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioNoiteActionPerformed(evt);
}
});
tempoGroup.add(jRadioFrio);
jRadioFrio.setFont(new java.awt.Font("Century", 0, 15)); // NOI18N
jRadioFrio.setText("frio");
jRadioFrio.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioFrioActionPerformed(evt);
}
});
tempoGroup.add(jRadioQuente);
jRadioQuente.setFont(new java.awt.Font("Century", 0, 15)); // NOI18N
jRadioQuente.setText("quente");
jRadioQuente.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioQuenteActionPerformed(evt);
}
});
lookGroup.add(jRadioFino);
jRadioFino.setFont(new java.awt.Font("Century", 0, 15)); // NOI18N
jRadioFino.setText("fino");
lookGroup.add(jRadioCasual);
jRadioCasual.setFont(new java.awt.Font("Century", 0, 15)); // NOI18N
jRadioCasual.setText("casual");
jRadioCasual.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioCasualActionPerformed(evt);
}
});
lookGroup.add(jRadioSerio);
jRadioSerio.setFont(new java.awt.Font("Century", 0, 15)); // NOI18N
jRadioSerio.setText("sério");
jRadioSerio.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioSerioActionPerformed(evt);
}
});
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null}
},
new String [] {
"ID", "Roupa"
}
) {
boolean[] canEdit = new boolean [] {
false, false
};
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
jScrollPane1.setViewportView(jTable1);
jTable1.getColumnModel().getColumn(0).setMinWidth(40);
jTable1.getColumnModel().getColumn(0).setMaxWidth(40);
jTable1.getColumnModel().getColumn(1).setResizable(false);
jButton2.setText("Cadastrar");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton1.setText("Cancelar");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabelOcasiao1.setFont(new java.awt.Font("Century Gothic", 0, 14)); // NOI18N
jLabelOcasiao1.setText("Insira o ID da roupa:");
jTextIdRoupa.setFont(new java.awt.Font("Century Gothic", 0, 30)); // NOI18N
jTextIdRoupa.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextIdRoupaActionPerformed(evt);
}
});
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.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(29, 29, 29)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(26, 26, 26))
.addGroup(layout.createSequentialGroup()
.addGap(115, 115, 115)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButtonMostrarRoupas)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 533, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jRadioFamilia)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabelOcasiao1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextIdRoupa))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabelOcasiao)
.addComponent(jRadioAmigos)
.addComponent(jRadioPaquera)
.addComponent(jRadioFacul))
.addGap(72, 72, 72)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jRadioNoite)
.addComponent(jRadioDia)
.addComponent(jLabelTempo))))
.addGap(85, 85, 85)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jRadioFrio)
.addComponent(jRadioQuente)
.addComponent(jLabelHorario))
.addGap(76, 76, 76)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jRadioCasual)
.addComponent(jRadioFino)
.addComponent(jRadioSerio)
.addComponent(jLabelLook))))
.addContainerGap(130, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(42, 42, 42)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabelOcasiao)
.addComponent(jLabelHorario)
.addComponent(jLabelLook)
.addComponent(jLabelTempo))
.addGap(35, 35, 35)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(jRadioFacul)
.addGap(18, 18, 18)
.addComponent(jRadioPaquera)
.addGap(18, 18, 18)
.addComponent(jRadioAmigos)
.addGap(18, 18, 18)
.addComponent(jRadioFamilia))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(jRadioQuente)
.addGap(18, 18, 18)
.addComponent(jRadioFrio))
.addGroup(layout.createSequentialGroup()
.addComponent(jRadioDia)
.addGap(18, 18, 18)
.addComponent(jRadioNoite)))
.addGap(90, 90, 90)))
.addGroup(layout.createSequentialGroup()
.addComponent(jRadioSerio)
.addGap(18, 18, 18)
.addComponent(jRadioCasual)
.addGap(18, 18, 18)
.addComponent(jRadioFino)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(12, 12, 12)
.addComponent(jLabelOcasiao1))
.addComponent(jTextIdRoupa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(29, 29, 29)
.addComponent(jButtonMostrarRoupas)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(59, 59, 59)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(33, 33, 33))
);
pack();
}// </editor-fold>
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
//ROUPA USADA
private void jButtonMostrarRoupasActionPerformed(java.awt.event.ActionEvent evt) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con2;
con2 = DriverManager.getConnection("jdbc:mysql://www.bancoexterno.com/banco", "user", "senha");
String query = "SELECT id, roupa FROM ParamRoupa";
PreparedStatement cmd;
cmd = con2.prepareStatement(query);
ResultSet rs;
rs = cmd.executeQuery();
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
model.setNumRows(0);
while (rs.next()) {
model.addRow(new Object[]{
rs.getString("id"),
rs.getString("roupa")
});
}
} catch (ClassNotFoundException ex) {
System.out.println("não foi possível encontrar a classe. Erro: -- "+ex+" --");
} catch (SQLException e) {
System.out.println("Erro no SQL. Erro: -- "+e+" --");
}
}
private void jRadioPaqueraActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jRadioAmigosActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jRadioNoiteActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jRadioFrioActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jRadioCasualActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jRadioSerioActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jRadioFaculActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jRadioQuenteActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
//cadastrar roupa vestida
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
try {
// TODO add your handling code here:
Class.forName("com.mysql.jdbc.Driver");
//variavel de conexao
Connection con3;
//conexao
con3 = DriverManager.getConnection("jdbc:mysql://www.bancoexterno.com/banco", "user", "senha");
//coleta o id da roupa digitado
String id = jTextIdRoupa.getText();
String ocasiao = ocasiaoGroup.getSelection().getActionCommand();
String horario = horarioGroup.getSelection().getActionCommand();
String tempo = tempoGroup.getSelection().getActionCommand();
String look = lookGroup.getSelection().getActionCommand();
//comando enviado ao sql
//String query = "UPDATE ParamRoupa SET "+ocasiao+"="+ocasiao+"+1, "+horario+"="+horario+"+1, "+tempo+"="+tempo+"+1, "+look+"="+look+"+1, WHERE id = " +id;
System.out.println(ocasiao);
System.out.println(horario);
System.out.println(tempo);
System.out.println(look);
//comando de inserção
//PreparedStatement stmt = con3.prepareStatement(query);
//executa os comandos no BD
//stmt.executeUpdate();
con3.close();
this.dispose();
} catch (ClassNotFoundException ex) {
System.out.println("não foi possível encontrar a classe. Erro -- "+ex+" --");
} catch (SQLException e) {
System.out.println("Erro no BD. Erro -- "+e+" --");
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
}
private void jTextIdRoupaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/*
* Set the Nimbus look and feel
*/
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/*
* If Nimbus (introduced in Java SE 6) is not available, stay with the
* default look and feel. For details see
* http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(RoupaUsada.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(RoupaUsada.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(RoupaUsada.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(RoupaUsada.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
* Create and display the dialog
*/
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
RoupaUsada dialog = new RoupaUsada(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.ButtonGroup horarioGroup;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButtonMostrarRoupas;
private javax.swing.JLabel jLabelHorario;
private javax.swing.JLabel jLabelLook;
private javax.swing.JLabel jLabelOcasiao;
private javax.swing.JLabel jLabelOcasiao1;
private javax.swing.JLabel jLabelTempo;
private javax.swing.JPanel jPanel1;
private javax.swing.JRadioButton jRadioAmigos;
private javax.swing.JRadioButton jRadioCasual;
private javax.swing.JRadioButton jRadioDia;
private javax.swing.JRadioButton jRadioFacul;
private javax.swing.JRadioButton jRadioFamilia;
private javax.swing.JRadioButton jRadioFino;
private javax.swing.JRadioButton jRadioFrio;
private javax.swing.JRadioButton jRadioNoite;
private javax.swing.JRadioButton jRadioPaquera;
private javax.swing.JRadioButton jRadioQuente;
private javax.swing.JRadioButton jRadioSerio;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextIdRoupa;
private javax.swing.ButtonGroup lookGroup;
private javax.swing.ButtonGroup ocasiaoGroup;
private javax.swing.ButtonGroup tempoGroup;
// End of variables declaration
}