Ir ao conteúdo
  • Cadastre-se

Fechar janela secundária sem fechar a primária


flp.bn

Posts recomendados

eu estou com um problema, eu criei uma janela primaria, e ao clicar em um botão ela abre uma janela secundária, porém ao fechar a janela secundária tambem fecha a janela primária

tá ai a janela primaria:

/*

* Ficha_escolar.java

*

* Created on 9 de Setembro de 2009, 10:15

*/

/**

*

* @author rm61350

*/

public class Ficha_escolar extends javax.swing.JFrame {

/** Creates new form Ficha_escolar */

public Ficha_escolar() {

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() {

jButton1 = new javax.swing.JButton();

jButton2 = new javax.swing.JButton();

jButton3 = new javax.swing.JButton();

jButton4 = new javax.swing.JButton();

jButton5 = new javax.swing.JButton();

jButton6 = new javax.swing.JButton();

jButton7 = new javax.swing.JButton();

jButton8 = new javax.swing.JButton();

menuBar = new javax.swing.JMenuBar();

fileMenu = new javax.swing.JMenu();

openMenuItem = new javax.swing.JMenuItem();

saveMenuItem = new javax.swing.JMenuItem();

saveAsMenuItem = new javax.swing.JMenuItem();

exitMenuItem = new javax.swing.JMenuItem();

editMenu = new javax.swing.JMenu();

cutMenuItem = new javax.swing.JMenuItem();

copyMenuItem = new javax.swing.JMenuItem();

pasteMenuItem = new javax.swing.JMenuItem();

deleteMenuItem = new javax.swing.JMenuItem();

helpMenu = new javax.swing.JMenu();

contentsMenuItem = new javax.swing.JMenuItem();

aboutMenuItem = new javax.swing.JMenuItem();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jButton1.setText("Escola");

jButton1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton1ActionPerformed(evt);

}

});

jButton2.setText("Curso");

jButton2.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton2ActionPerformed(evt);

}

});

jButton3.setText("Cadastrar Professor");

jButton3.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton3ActionPerformed(evt);

}

});

jButton4.setText("Dados Professor");

jButton4.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton4ActionPerformed(evt);

}

});

jButton5.setText("Cadastrar Funcionário");

jButton5.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton5ActionPerformed(evt);

}

});

jButton6.setText("Dados Funcionário");

jButton6.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton6ActionPerformed(evt);

}

});

jButton7.setText("Cadastrar Aluno");

jButton7.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton7ActionPerformed(evt);

}

});

jButton8.setText("Dados Aluno");

jButton8.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton8ActionPerformed(evt);

}

});

fileMenu.setText("File");

openMenuItem.setText("Open");

fileMenu.add(openMenuItem);

saveMenuItem.setText("Save");

fileMenu.add(saveMenuItem);

saveAsMenuItem.setText("Save As ...");

fileMenu.add(saveAsMenuItem);

exitMenuItem.setText("Exit");

exitMenuItem.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

exitMenuItemActionPerformed(evt);

}

});

fileMenu.add(exitMenuItem);

menuBar.add(fileMenu);

editMenu.setText("Edit");

cutMenuItem.setText("Cut");

editMenu.add(cutMenuItem);

copyMenuItem.setText("Copy");

editMenu.add(copyMenuItem);

pasteMenuItem.setText("Paste");

editMenu.add(pasteMenuItem);

deleteMenuItem.setText("Delete");

editMenu.add(deleteMenuItem);

menuBar.add(editMenu);

helpMenu.setText("Help");

contentsMenuItem.setText("Contents");

helpMenu.add(contentsMenuItem);

aboutMenuItem.setText("About");

helpMenu.add(aboutMenuItem);

menuBar.add(helpMenu);

setJMenuBar(menuBar);

org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(layout.createSequentialGroup()

.addContainerGap()

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(jButton3)

.add(jButton5)

.add(jButton1)

.add(jButton7))

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 82, Short.MAX_VALUE)

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(jButton4)

.add(jButton6)

.add(jButton2)

.add(jButton8))

.addContainerGap(44, Short.MAX_VALUE))

);

layout.setVerticalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(layout.createSequentialGroup()

.addContainerGap()

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)

.add(jButton1)

.add(jButton2))

.add(45, 45, 45)

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)

.add(jButton3)

.add(jButton4))

.add(50, 50, 50)

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)

.add(jButton5)

.add(jButton6))

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 51, Short.MAX_VALUE)

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)

.add(jButton7)

.add(jButton8))

.add(30, 30, 30))

);

pack();

}// </editor-fold>

private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {

System.exit(0);

}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

new JanelaEscola().setVisible(true); // TODO add your handling code here:

}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

new JanelaCurso().setVisible(true); // TODO add your handling code here:

}

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

new CadastrarProfessor().setVisible(true); // TODO add your handling code here:

}

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {

new DadoProfessor().setVisible(true); // TODO add your handling code here:

}

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {

new CadastrarFuncionario().setVisible(true); // TODO add your handling code here:

}

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {

new DadosFuncionario().setVisible(true);// TODO add your handling code here:

}

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {

new CadastrarAluno().setVisible(true);// TODO add your handling code here:

}

private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {

new DadoAluno().setVisible(true);// TODO add your handling code here:

}

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new Ficha_escolar().setVisible(true);

}

});

}

// Variables declaration - do not modify

private javax.swing.JMenuItem aboutMenuItem;

private javax.swing.JMenuItem contentsMenuItem;

private javax.swing.JMenuItem copyMenuItem;

private javax.swing.JMenuItem cutMenuItem;

private javax.swing.JMenuItem deleteMenuItem;

private javax.swing.JMenu editMenu;

private javax.swing.JMenuItem exitMenuItem;

private javax.swing.JMenu fileMenu;

private javax.swing.JMenu helpMenu;

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.JMenuBar menuBar;

private javax.swing.JMenuItem openMenuItem;

private javax.swing.JMenuItem pasteMenuItem;

private javax.swing.JMenuItem saveAsMenuItem;

private javax.swing.JMenuItem saveMenuItem;

// End of variables declaration

}

tá ai a janela secundaria:

/*

* JanelaCurso.java

*

* Created on 9 de Setembro de 2009, 10:17

*/

/**

*

* @author rm61350

*/

public class JanelaCurso extends javax.swing.JFrame {

/** Creates new form JanelaCurso */

public JanelaCurso() {

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() {

jLabel1 = new javax.swing.JLabel();

jTextField1 = new javax.swing.JTextField();

jLabel2 = new javax.swing.JLabel();

jTextField2 = new javax.swing.JTextField();

jLabel3 = new javax.swing.JLabel();

jScrollPane1 = new javax.swing.JScrollPane();

jList1 = new javax.swing.JList();

jLabel4 = new javax.swing.JLabel();

jScrollPane2 = new javax.swing.JScrollPane();

jList2 = new javax.swing.JList();

jButton1 = new javax.swing.JButton();

jButton2 = new javax.swing.JButton();

jButton3 = new javax.swing.JButton();

menuBar = new javax.swing.JMenuBar();

fileMenu = new javax.swing.JMenu();

openMenuItem = new javax.swing.JMenuItem();

saveMenuItem = new javax.swing.JMenuItem();

saveAsMenuItem = new javax.swing.JMenuItem();

exitMenuItem = new javax.swing.JMenuItem();

editMenu = new javax.swing.JMenu();

cutMenuItem = new javax.swing.JMenuItem();

copyMenuItem = new javax.swing.JMenuItem();

pasteMenuItem = new javax.swing.JMenuItem();

deleteMenuItem = new javax.swing.JMenuItem();

helpMenu = new javax.swing.JMenu();

contentsMenuItem = new javax.swing.JMenuItem();

aboutMenuItem = new javax.swing.JMenuItem();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setText("Curso");

jTextField1.setText("jTextField1");

jLabel2.setText("Código do Curso");

jTextField2.setText("jTextField2");

jLabel3.setText("Professor");

jList1.setModel(new javax.swing.AbstractListModel() {

String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };

public int getSize() { return strings.length; }

public Object getElementAt(int i) { return strings; }

});

jScrollPane1.setViewportView(jList1);

jLabel4.setText("Disciplinas");

jList2.setModel(new javax.swing.AbstractListModel() {

String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };

public int getSize() { return strings.length; }

public Object getElementAt(int i) { return strings; }

});

jScrollPane2.setViewportView(jList2);

jButton1.setText("Anterior");

jButton2.setText("Próximo");

jButton3.setText("Fechar");

jButton3.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton3ActionPerformed(evt);

}

});

fileMenu.setText("File");

openMenuItem.setText("Open");

fileMenu.add(openMenuItem);

saveMenuItem.setText("Save");

fileMenu.add(saveMenuItem);

saveAsMenuItem.setText("Save As ...");

fileMenu.add(saveAsMenuItem);

exitMenuItem.setText("Exit");

exitMenuItem.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

exitMenuItemActionPerformed(evt);

}

});

fileMenu.add(exitMenuItem);

menuBar.add(fileMenu);

editMenu.setText("Edit");

cutMenuItem.setText("Cut");

editMenu.add(cutMenuItem);

copyMenuItem.setText("Copy");

editMenu.add(copyMenuItem);

pasteMenuItem.setText("Paste");

editMenu.add(pasteMenuItem);

deleteMenuItem.setText("Delete");

editMenu.add(deleteMenuItem);

menuBar.add(editMenu);

helpMenu.setText("Help");

contentsMenuItem.setText("Contents");

helpMenu.add(contentsMenuItem);

aboutMenuItem.setText("About");

helpMenu.add(aboutMenuItem);

menuBar.add(helpMenu);

setJMenuBar(menuBar);

org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(layout.createSequentialGroup()

.addContainerGap()

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(layout.createSequentialGroup()

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(jLabel3)

.add(jLabel1)

.add(jLabel2)

.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.add(layout.createSequentialGroup()

.add(25, 25, 25)

.add(jButton1)))

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(layout.createSequentialGroup()

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 81, Short.MAX_VALUE)

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(jLabel4)

.add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

.add(95, 95, 95))

.add(layout.createSequentialGroup()

.add(49, 49, 49)

.add(jButton2)

.add(50, 50, 50)

.add(jButton3)

.add(36, 36, 36))))

.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)

.add(org.jdesktop.layout.GroupLayout.LEADING, jTextField1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)

.add(jTextField2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE))

.addContainerGap())))

);

layout.setVerticalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(layout.createSequentialGroup()

.addContainerGap()

.add(jLabel1)

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)

.add(jLabel2)

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)

.add(jLabel3)

.add(jLabel4))

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 59, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 59, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

.add(33, 33, 33)

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)

.add(jButton3)

.add(jButton1)

.add(jButton2))

.addContainerGap(35, Short.MAX_VALUE))

);

pack();

}// </editor-fold>

private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {

System.exit(0);

}

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

System.exit(0); // TODO add your handling code here:

}

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new JanelaCurso().setVisible(true);

}

});

}

// Variables declaration - do not modify

private javax.swing.JMenuItem aboutMenuItem;

private javax.swing.JMenuItem contentsMenuItem;

private javax.swing.JMenuItem copyMenuItem;

private javax.swing.JMenuItem cutMenuItem;

private javax.swing.JMenuItem deleteMenuItem;

private javax.swing.JMenu editMenu;

private javax.swing.JMenuItem exitMenuItem;

private javax.swing.JMenu fileMenu;

private javax.swing.JMenu helpMenu;

private javax.swing.JButton jButton1;

private javax.swing.JButton jButton2;

private javax.swing.JButton jButton3;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JLabel jLabel3;

private javax.swing.JLabel jLabel4;

private javax.swing.JList jList1;

private javax.swing.JList jList2;

private javax.swing.JScrollPane jScrollPane1;

private javax.swing.JScrollPane jScrollPane2;

private javax.swing.JTextField jTextField1;

private javax.swing.JTextField jTextField2;

private javax.swing.JMenuBar menuBar;

private javax.swing.JMenuItem openMenuItem;

private javax.swing.JMenuItem pasteMenuItem;

private javax.swing.JMenuItem saveAsMenuItem;

private javax.swing.JMenuItem saveMenuItem;

// End of variables declaration

}

eu utilizo o netbeans 6.0

PS: ao abrir a janela principal clique em curso para abrir a janela secundária que coloquei aqui...

  • Curtir 1
Link para o comentário
Compartilhar em outros sites

É isso mesmo, como o js_junior07 exemplificou, fazendo isso você resolve o problema, já que a instrução EXIT_ON_CLOSE encerra a aplicação toda, juntamente com todas as janelas que a compõem, enquanto que a instrução HIDE_ON_CLOSE simplesmente oculta a janela secundária enquanto a janela principal e a aplicação continuam executando.

  • Curtir 1
Link para o comentário
Compartilhar em outros sites

consegui resolver o problema, fui mexendo e descobri

na janela JanelaCurso.java tinha uma parte q estava assim

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

System.exit(0); // TODO add your handling code here:

}

ai eu modifiquei para

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

this.setDefaultCloseOperation( DadosFuncionario.DISPOSE_ON_CLOSE );

this.setVisible(false);

this.dispose();

}

e quando eu rodei fechou somente a janela secundária..

valeu galera pela ajuda

Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novos posts.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

Curso de Hacker Ético

LANÇAMENTO!

CLIQUE AQUI E CONFIRA!

* Este curso não é ministrado pela equipe do Clube do Hardware.