Bom Dia !!
Tenho esse codigo e queria saber como faço para no ActionPerformed do Boato btnok na parte em quye jrnome está selecionado para aparecer o resultado da consulta na jTable1
package alimentar;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
public class itens extends JFrame {
JPanel jPanel1 = new JPanel();
JTextField txtprocurar = new JTextField();
JLabel jLabel1 = new JLabel();
JButton btnok = new JButton();
ButtonGroup buttonGroup1 = new ButtonGroup();
JRadioButton jrnome = new JRadioButton();
JRadioButton jrgrupo = new JRadioButton();
JRadioButton jrmarca = new JRadioButton();
JScrollPane jScrollPane1 = new JScrollPane();
JTable jTable1 = new JTable();
public itens() {
try {
jbInit();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
void jbInit() throws Exception {
this.getContentPane().setLayout(null);
this.setSize(new Dimension(510, 315));
this.setTitle("Procurar Itens");
jPanel1.setBounds(new Rectangle( -1, 0, 509, 295));
jPanel1.setLayout(null);
txtprocurar.setText("");
txtprocurar.setBounds(new Rectangle(19, 66, 151, 19));
jLabel1.setText("Procurar por:");
jLabel1.setBounds(new Rectangle(20, 17, 93, 15));
btnok.setBounds(new Rectangle(18, 259, 88, 25));
btnok.setText("OK");
btnok.addActionListener(new itens_btnok_actionAdapter(this));
jrnome.setText("Nome");
jrnome.setBounds(new Rectangle(16, 31, 63, 23));
jrgrupo.setText("Grupo");
jrgrupo.setBounds(new Rectangle(86, 31, 66, 23));
jrmarca.setText("Marca");
jrmarca.setBounds(new Rectangle(154, 31, 64, 23));
jScrollPane1.setBounds(new Rectangle(19, 88, 465, 167));
this.getContentPane().add(jPanel1, null);
jPanel1.add(jLabel1, null);
jPanel1.add(jrnome, null);
jPanel1.add(jrmarca, null);
jPanel1.add(jrgrupo, null);
jPanel1.add(txtprocurar, null);
jPanel1.add(btnok, null);
jPanel1.add(jScrollPane1, null);
jScrollPane1.getViewport().add(jTable1, null);
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object[][] {}
,
new String[] {"Item", "Marca", "Grupo", "Preço á Prazo",
"Preço á Vista"}));
jTable1.getColumnModel().getColumn(0).setPreferredWidth(200);
jTable1.getColumnModel().getColumn(1).setPreferredWidth(100);
jTable1.getColumnModel().getColumn(2).setPreferredWidth(100);
jTable1.getColumnModel().getColumn(3).setPreferredWidth(100);
jTable1.getColumnModel().getColumn(4).setPreferredWidth(100);
buttonGroup1.add(jrnome);
buttonGroup1.add(jrgrupo);
buttonGroup1.add(jrmarca);
jrnome.setSelected(true);
}
void btnok_actionPerformed(ActionEvent e) {
new conexao();
if (jrnome.isSelected() == true)
JOptionPane.showMessageDialog(null, "Nome");
Vector dod = new Vector();
Vector column = new Vector();
Vector lin = new Vector();
ResultSetMetaData rsmd;
ResultSet rs;
try {
Statement st = alimentar.conexao.con.createStatement();
rs = st.executeQuery("SELECT descricao , marca , grupo , preco_prazo , preco_venda FROM produtos WHERE descricao = '" +
txtprocurar.getText() + "'");
rsmd = rs.getMetaData();
for (int col = 1; col <= rsmd.getColumnCount(); col++)
column.add(rsmd.getColumnName(col));
while (rs.next()) {
dod.addElement(rs.getString(1));
dod.addElement(rs.getString(2));
dod.addElement(rs.getString(3));
dod.addElement(Float.toString(rs.getFloat(4)));
dod.addElement(Float.toString(rs.getFloat(5)));
lin.addElement(dod);
dod = new Vector();
}
}
catch (Exception ec) {
JOptionPane.showMessageDialog(null, ec);
}
if (jrmarca.isSelected() == true)
JOptionPane.showMessageDialog(null, "Marca");
if (jrgrupo.isSelected() == true)
JOptionPane.showMessageDialog(null, "Grupo");
}
class itens_btnok_actionAdapter
implements java.awt.event.ActionListener {
itens adaptee;
itens_btnok_actionAdapter(itens adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnok_actionPerformed(e);
}
}
}