Olá amigos
tenho um frame de cadastro de clientes que num tderminado momento chama outro frame, acontece que o frame secnudário não fica ativo, ele fecha logo. Segue o codigo:
frame principal.
stmt = bd.ConexaoBancoDados.conexao().createStatement();
nomecliente = jTextField2.getText();
if (macao.equals("I")) {
JFrame TrabBancoEJTable = new TrabBancoEJTable();
TrabBancoEJTable.setVisible(true);
TrabBancoEJTable.dispose();
}
frame secundário.
/*
* TrabBancoEJTable.java
*
* Created on 19 de Agosto de 2008, 09:57
*/
package assistenciadesktop;
import java.awt.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import java.sql.*;
import java.util.*;
import assistenciadesktop.Listaclientes;
import bd.ConexaoBancoDados;
/**
*
* @author silvio
*/
public class TrabBancoEJTable extends javax.swing.JFrame {
private JTable jTable = null;
private java.sql.Statement stmt;
/** Creates new form TrabBancoEJTable */
public TrabBancoEJTable() throws HeadlessException, ClassNotFoundException {
initialize();
}
public TrabBancoEJTable(GraphicsConfiguration gc) throws ClassNotFoundException {
super();
initialize();
}
public TrabBancoEJTable(String title) throws HeadlessException, ClassNotFoundException {
super();
initialize();
}
public TrabBancoEJTable(String title, GraphicsConfiguration gc) throws ClassNotFoundException {
super(title,gc);
initialize();
}
private Vector getProximaLinha(ResultSet rs, ResultSetMetaData rsmd)
throws SQLException{
Vector linhaAtual = new Vector();
for (int i=1; i<=rsmd.getColumnCount() ; i++)
linhaAtual.addElement(rs.getString(i));
return linhaAtual;
}
private void mostrarResultados(ResultSet rs) throws SQLException {
boolean dados = rs.next();
if (!dados ) {
JOptionPane.showMessageDialog(this, "Nehum registro encontrado");
return;
}
Vector colunas = new Vector();
Vector linhas = new Vector();
try {
ResultSetMetaData rsmd = rs.getMetaData();
for (int i=1 ; i<=rsmd.getColumnCount(); i++)
colunas .addElement(rsmd.getColumnName(i));
do {
linhas.addElement(getProximaLinha(rs, rsmd));
} while (rs.next());
jTable = new JTable(linhas, colunas);
JScrollPane jScrollPane = new JScrollPane(jTable);
getContentPane().add(jScrollPane,java.awt.BorderLayout.CENTER);
validate();
}
catch ( SQLException sqlex) {sqlex.printStackTrace(); }
}
private void getJTable() throws ClassNotFoundException{
Statement statement;
ResultSet result;
try {
stmt = bd.ConexaoBancoDados.conexao().createStatement();
String query = "select id,nome,telefone from clientes where upper(nome) ilike "+"upper('%"+
Listaclientes.nomecliente+"%') order by nome";
ResultSet rs = stmt.executeQuery(query);
mostrarResultados(rs);
stmt.close();
}
catch (SQLException sqlex) {sqlex.printStackTrace();}
}
/** 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() {
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setName("Form"); // NOI18N
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
try {
new TrabBancoEJTable().setVisible(true);
} catch (HeadlessException ex) {
Logger.getLogger(TrabBancoEJTable.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(TrabBancoEJTable.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
}
private void initialize() throws ClassNotFoundException {
this.setLocationRelativeTo(null);
getJTable();
this.setSize(400,300);
this.setTitle("Clientes");
//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
// Variables declaration - do not modify
// End of variables declaration
}
se alguém puder ajudar?
Muito obrigado
Silvio Guedes
