Criei uma classe que contem o frame principal e um JInternalFrame e uma classe que contem outro JInternalFrame. Na classe do frame principal tem um item do menu que tem a função de chamar o outro JInternalFrame, só que na hora de chamar esse JInternalFrame não acontece nada. Qual será o meu erro? Aqui vai o código…
Essa é classe principal
public class Cadastro extends javax.swing.JFrame {
/** Creates new form Cadastro */
public Cadastro() {
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.
*/
private void initComponents() {
jDesktopPane1 = new javax.swing.JDesktopPane();
jInternalFrame1 = new javax.swing.JInternalFrame();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
getContentPane().setLayout(null);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
getContentPane().add(jDesktopPane1);
jDesktopPane1.setBounds(40, 20, 0, 0);
jInternalFrame1.setVisible(true);
getContentPane().add(jInternalFrame1);
jInternalFrame1.setBounds(20, 60, 270, 160);
jMenu1.setText("Menu");
jMenuItem1.setText("Abrir JInternal Frame");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem1);
jMenuBar1.add(jMenu1);
setJMenuBar(jMenuBar1);
pack();
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setSize(new java.awt.Dimension(400, 300));
setLocation((screenSize.width-400)/2,(screenSize.height-300)/2);
}
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
[b]new teste().show(); [/b] [b]Acho que meu erro esta aqui...... [/b]
}
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new Cadastro().show();
}
// Variables declaration - do not modify
private javax.swing.JInternalFrame jInternalFrame1;
private javax.swing.JDesktopPane jDesktopPane1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenu jMenu1;
// End of variables declaration
}
E essa a classe que contem o JInternalFrame
public class teste extends javax.swing.JInternalFrame {
/** Creates new form teste */
public teste() {
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.
*/
private void initComponents() {
pack();
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setSize(new java.awt.Dimension(200, 100));
setLocation((screenSize.width-200)/2,(screenSize.height-100)/2);
}
// Variables declaration - do not modify
// End of variables declaration
}