Cara certamente quando vc fechar uma jframe e ela fecha toda a aplicação é pq ela está setada pra funcionar dessa maneira… não acho outro jeito de isso acontecer, mas por via das duvidas poste o codigo inteiro da jframe que vc criou (AdicionarCd).
O
others
packagefichapratica9;/** * * @author Administrador */publicclassAdicionarCdextendsjavax.swing.JFrame{Bibliotecabib=newBiblioteca();Cdcdx1=newCd();/** Creates new form AdicionarCd */publicAdicionarCd(){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 "> privatevoidinitComponents(){jLabel1=newjavax.swing.JLabel();jTextField1=newjavax.swing.JTextField();jTextField2=newjavax.swing.JTextField();jLabel2=newjavax.swing.JLabel();jLabel3=newjavax.swing.JLabel();jButton1=newjavax.swing.JButton();setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);jLabel1.setText("Adicionar CD");jLabel2.setText("Titulo:");jLabel3.setText("Artista:");jButton1.setText("Inserir");jButton1.addActionListener(newjava.awt.event.ActionListener(){publicvoidactionPerformed(java.awt.event.ActionEventevt){jButton1ActionPerformed(evt);}});javax.swing.GroupLayoutlayout=newjavax.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().addContainerGap().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel2).addComponent(jLabel3)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jTextField2,javax.swing.GroupLayout.Alignment.LEADING,javax.swing.GroupLayout.DEFAULT_SIZE,240,Short.MAX_VALUE).addComponent(jTextField1,javax.swing.GroupLayout.DEFAULT_SIZE,240,Short.MAX_VALUE))).addGroup(layout.createSequentialGroup().addGap(113,113,113).addComponent(jLabel1)).addGroup(layout.createSequentialGroup().addGap(112,112,112).addComponent(jButton1))).addContainerGap()));layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLabel1).addGap(23,23,23).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel2).addComponent(jTextField1,javax.swing.GroupLayout.PREFERRED_SIZE,javax.swing.GroupLayout.DEFAULT_SIZE,javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(20,20,20).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel3).addComponent(jTextField2,javax.swing.GroupLayout.PREFERRED_SIZE,javax.swing.GroupLayout.DEFAULT_SIZE,javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,29,Short.MAX_VALUE).addComponent(jButton1).addGap(26,26,26)));pack();}// </editor-fold> privatevoidjButton1ActionPerformed(java.awt.event.ActionEventevt){cdx1.setArtista(jTextField1.getText());cdx1.setTitulo(jTextField2.getText());bib.enterCd(cdx1);}/** * @param args the command line arguments */publicstaticvoidmain(Stringargs[]){java.awt.EventQueue.invokeLater(newRunnable(){publicvoidrun(){newAdicionarCd().setVisible(true);}});}// Variables declaration - do not modify privatejavax.swing.JButtonjButton1;privatejavax.swing.JLabeljLabel1;privatejavax.swing.JLabeljLabel2;privatejavax.swing.JLabeljLabel3;privatejavax.swing.JTextFieldjTextField1;privatejavax.swing.JTextFieldjTextField2;// End of variables declaration }
O
others
nao percebi muito bem a forma de implementar isso
O
others
Obrigado pessoal está a funcionar Abraço
Joao
Luiz_Rocha
Opa, companheiro!
Essa é simples: existe um método que eu uso na JFrame chamado
setDefaultCloseOperation(inti)
Use esse método no construtor da sua JFrame para mudar a configuração default para o que ela faz quando vc clica no X. Para isso envie como argumento a constante que vc quiser, dentre estas:
javax.swing.WindowConstants
DISPOSE_ON_CLOSE ou 2 // ?
DO_NOTHING_ON_CLOSE ou 0 // vc já sabe
EXIT_ON_CLOSE ou 3 // fecha todo o projeto
HIDE_ON_CLOSE ou 1 //esconde, mas conserva os atributos
//esconder janela ao clicar no X:setDefaultCloseOperation(HIDE_ON_CLOSE);//ou: fazer alguma coisa q eu n lembro:setDefaultCloseOperation(DISPOSE_ON_CLOSE);//ou: fechar tudo ao clicar no x:setDefaultCloseOperation(EXIT_ON_CLOSE);//ou: fazer nada ao clicar no x:setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
Pronto, melhor: no teu caso, eu botava o seguinte:
(isso abaixo foi retirado do teu código)
publicclassAdicionarCdextendsjavax.swing.JFrame{Bibliotecabib=newBiblioteca();Cdcdx1=newCd();/** Creates new form AdicionarCd */publicAdicionarCd(){initComponents();this.setDefaultCloseOperation(HIDE_ON_CLOSE);// n.b.: acho que fica melhor com DISPOSE_ON_CLOSE, melhor tentar com oos dois.Oo “this.” é opcional.}