Olá galera!
tenho duas classes…
/*
* JanPrinc.java
*
* Created on 27 de Agosto de 2007, 19:57
*/
package br.com.amigos.gui;
import java.beans.PropertyVetoException;
import java.sql.Connection;
public class JanPrinc extends javax.swing.JFrame {
/** Creates new form JanPrinc */
public JanPrinc(Connection p_conn) {
initComponents();
setExtendedState(MAXIMIZED_BOTH);
setVisible(true);
this.conn = p_conn;
}
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jDesktopPane1 = new javax.swing.JDesktopPane();
jMenuBar2 = new javax.swing.JMenuBar();
jMenu2 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
getContentPane().setLayout(new java.awt.GridLayout(1, 0));
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Sistema dos Amigos - Menu Principal");
getContentPane().add(jDesktopPane1);
jMenu2.setText("Arquivo");
jMenuItem1.setText("Cidades");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem1);
jMenuItem2.setText("Sair");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem2);
jMenuBar2.add(jMenu2);
setJMenuBar(jMenuBar2);
pack();
}// </editor-fold>
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
frmCidades cidades = new frmCidades();
jDesktopPane1.add(cidades);
}
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0);
}
/**
* @param args the command line arguments
*/
/* public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new JanPrinc().setVisible(true);
}
});
}*/
// Variables declaration - do not modify
private javax.swing.JDesktopPane jDesktopPane1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar2;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
// End of variables declaration
private java.sql.Connection conn;
}
/*
* frmCidades.java
*
* Created on 7 de Setembro de 2007, 09:28
*/
package br.com.amigos.gui;
import br.com.amigos.util.Mascaras;
/**
*
* @author root
*/
public class frmCidades extends javax.swing.JInternalFrame {
/** Creates new form frmCidades */
public frmCidades() {
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.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
codi_cidade = new javax.swing.JFormattedTextField(mask.getMaskInteiro());
jPanel1 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
nome_cidade = new javax.swing.JFormattedTextField(mask.getMaskNome());
uf_cidade = new javax.swing.JFormattedTextField(mask.getMaskUF());
jPanel2 = new javax.swing.JPanel();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jButton8 = new javax.swing.JButton();
jButton7 = new javax.swing.JButton();
setClosable(true);
setIconifiable(true);
setMaximizable(true);
setResizable(true);
setTitle("Cadastro de Cidades");
setDesktopIcon(null);
setFrameIcon(null);
setOpaque(false);
try {
setSelected(true);
} catch (java.beans.PropertyVetoException e1) {
e1.printStackTrace();
}
codi_cidade.setFocusLostBehavior(javax.swing.JFormattedTextField.COMMIT);
jPanel1.setLayout(new java.awt.GridLayout(1, 4));
jButton1.setText("|<");
jPanel1.add(jButton1);
jButton2.setText("<");
jPanel1.add(jButton2);
jButton3.setText(">");
jPanel1.add(jButton3);
jButton4.setText(">|");
jPanel1.add(jButton4);
jLabel1.setText("C\u00f3digo:");
jLabel2.setText("Nome:");
jLabel3.setText("UF:");
nome_cidade.setFocusLostBehavior(javax.swing.JFormattedTextField.COMMIT);
uf_cidade.setFocusLostBehavior(javax.swing.JFormattedTextField.COMMIT);
jPanel2.setLayout(new java.awt.GridLayout(1, 4));
jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
jButton5.setText("Inserir");
jPanel2.add(jButton5);
jButton6.setText("Gravar");
jPanel2.add(jButton6);
jButton8.setText("Filtrar");
jPanel2.add(jButton8);
jButton7.setText("Excluir");
jPanel2.add(jButton7);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(24, 24, 24)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(codi_cidade, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(uf_cidade, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(nome_cidade))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 373, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(codi_cidade, javax.swing.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.addComponent(jLabel1))
.addComponent(jPanel1, 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(jLabel2)
.addComponent(nome_cidade, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(uf_cidade, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();
}// </editor-fold>
// Variables declaration - do not modify
private javax.swing.JFormattedTextField codi_cidade;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton8;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JFormattedTextField nome_cidade;
private javax.swing.JFormattedTextField uf_cidade;
// End of variables declaration
private Mascaras mask = new Mascaras();
}
Compila, roda, mas quanto acesso o menu que deveria abrir a JInternalFrame, nao acontece nada, nem exception, nem nada… será que alguem pode dar uma luz?
A… se eu colocar
cidades.setVisible(true);
acusa erro e NullPointerException.
Obrigado
Douglas