Pessoal, estou tentando abrir uma caixa de diálogo para dizer que o cadastro foi efetuado com sucesso.
Já tentei abrir um outro jinternalframe, tentei usar o System.out.print, e nada. A última tentativa foi…
JOptionPane.showMessageDialog(null, "Ok");
…mas também não funciona. Estou usando netbeans para o projeto que, por coincidência é meu primeiro estou estudando java montando um projetinho simples, só para incluir, ver, editar e excluir registros do db.
O código do meu arquivo é o seguinte:
[code]/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
/*
- cadEspecialidade.java
- Created on 23/07/2010, 14:05:48
*/
package visao.gui.cadastros;
import java.awt.Dimension;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.JOptionPane;
/**
*
-
@author tiago
*/
public class cadEspecialidade extends javax.swing.JInternalFrame {/** Creates new form cadEspecialidade */
public cadEspecialidade() {
initComponents();
}public void setPosicao(){
Dimension d = this.getDesktopPane().getSize();
this.setLocation((d.width - this.getSize().width)/2,
(d.height - this.getSize().height)/2);
}/** 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”)
//
private void initComponents() {labelNome = new javax.swing.JLabel();
fNome = new javax.swing.JTextField();
btCadastrar = new javax.swing.JButton();
btFechar = new javax.swing.JButton();setClosable(true);
setMaximizable(true);
setResizable(true);
setTitle(“Cadastro de especialidades”);labelNome.setText(“Nome da especialidade:”);
btCadastrar.setText(“Cadastrar”);
btCadastrar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btCadastrarActionPerformed(evt);
}
});btFechar.setText(“Fechar”);
btFechar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btFecharActionPerformed(evt);
}
});javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(fNome, javax.swing.GroupLayout.DEFAULT_SIZE, 370, Short.MAX_VALUE)
.addComponent(labelNome)
.addGroup(layout.createSequentialGroup()
.addComponent(btCadastrar)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btFechar)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(labelNome)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(fNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btCadastrar)
.addComponent(btFechar))
.addContainerGap(16, Short.MAX_VALUE))
);pack();
}//
private void btCadastrarActionPerformed(java.awt.event.ActionEvent evt) {
try {
try {
Class.forName(“org.postgresql.Driver”);
} catch (ClassNotFoundException ex) {
Logger.getLogger(cadEspecialidade.class.getName()).log(Level.SEVERE, null, ex);
}
Connection con = DriverManager.getConnection(“jdbc:postgresql://localhost:5433/marcapp”, “postgres”, “paico”);
Statement stm = con.createStatement();
String SQL = “INSERT INTO especialidades (nome) VALUES (’”+fNome.getText()+"’)";
stm.executeQuery(SQL);
JOptionPane.showMessageDialog(null, “Ok”);
} catch (SQLException ex) {
Logger.getLogger(cadEspecialidade.class.getName()).log(Level.SEVERE, null, ex);
}
}private void btFecharActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
}// Variables declaration - do not modify
private javax.swing.JButton btCadastrar;
private javax.swing.JButton btFechar;
private javax.swing.JTextField fNome;
private javax.swing.JLabel labelNome;
// End of variables declaration
}
[/code] -
Desde já agradeço a atenção de todos!