Foros del Web » Programación para mayores de 30 ;) » Java »

Se cierran todas las ventanas {swing}

Estas en el tema de Se cierran todas las ventanas {swing} en el foro de Java en Foros del Web. Estoy utilizando Netbeans ... y swing,quiero que al darle click en un boton,abra otra ventana, ok, eso ya lo tengo,pero el problema es que si ...
  #1 (permalink)  
Antiguo 30/10/2006, 08:40
Avatar de B**
B**
 
Fecha de Ingreso: enero-2006
Ubicación: Monterrey,Mexico
Mensajes: 952
Antigüedad: 18 años, 3 meses
Puntos: 3
Se cierran todas las ventanas {swing}

Estoy utilizando Netbeans ... y swing,quiero que al darle click en un boton,abra otra ventana, ok, eso ya lo tengo,pero el problema es que si cierro alguna de las ventanas (aplicaciones swing) se cierran todas !... eso no me pasa en eclipse..pero en eclipse no puedo utilizar el GroupLayout...
Para abrir, uso:
Código HTML:
 busqueda bs= new busqueda();
 bs.setVisible(true);
Alguien sabe por que pasa esto?
Gracias de antemano
...
__________________
-URL= Go PHP5.
-Age=22.
-Learning=PHP,J2EE,Struts,MAMBO,C++,JSON,AJAX,XHTML ,CSS.
  #2 (permalink)  
Antiguo 30/10/2006, 09:22
 
Fecha de Ingreso: octubre-2003
Mensajes: 3.578
Antigüedad: 20 años, 6 meses
Puntos: 51
¿Como cierras la ventana? ¿System.exit(0)?
  #3 (permalink)  
Antiguo 30/10/2006, 09:40
Avatar de B**
B**
 
Fecha de Ingreso: enero-2006
Ubicación: Monterrey,Mexico
Mensajes: 952
Antigüedad: 18 años, 3 meses
Puntos: 3
Olvide ese detalle... lo que pasa que si cierro la ventana con la "X" , osea como una ventana normal de windows... se cierra todo.... no es de que haya programado un boton para cerrar.
__________________
-URL= Go PHP5.
-Age=22.
-Learning=PHP,J2EE,Struts,MAMBO,C++,JSON,AJAX,XHTML ,CSS.
  #4 (permalink)  
Antiguo 30/10/2006, 11:55
 
Fecha de Ingreso: octubre-2003
Mensajes: 3.578
Antigüedad: 20 años, 6 meses
Puntos: 51
En Java darle a la X no hace nada, o no deberia, a no ser que le hayas asignado un evento, asi que algo le debes estar haciendo para que se cierre.

De hecho una de las primeras cosas que pasa al hacer un programa en Java es que la gente se olvida de asignar un evento a la X y luego no pueden "cerrarla" .

Quiza con algo de codigo, por que asi adivinando.. es dificil.
  #5 (permalink)  
Antiguo 30/10/2006, 12:22
Avatar de B**
B**
 
Fecha de Ingreso: enero-2006
Ubicación: Monterrey,Mexico
Mensajes: 952
Antigüedad: 18 años, 3 meses
Puntos: 3
Eso pasa al hacer un jar? Lo que pasa que estoy en netbeans y al a hora de correr la aplicacion ahi mismo ... es donde si doy click en la X(hablamos de la x de cerrar,que esta a lado de maximizar,etc) cierra todas las ventanas..
Por lo menos yo no he agregado un evento... a no ser que netbeans solo lo genere, te dejo el codigo por si le quieres hechar un vistaso:
Código PHP:
/*
 * principal.java
 *
 * Created on 13 de octubre de 2006, 06:53 AM
 */

package cfe.medicion;
import java.awt.event.ActionEvent;
import javax.swing.*;
import javax.swing.event.*;

/**
 *
 * @author  TDD060-01
 */

public class principal extends javax.swing.JFrame{
    
    
/**
     * Creates new form principal
     */
    
public principal() {
        
initComponents();
        
inic();
      
    }
    
    
/** 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() {
       
//declaracion de elementos GUI

        
org.jdesktop.layout.GroupLayout jDialog1Layout = new org.jdesktop.layout.GroupLayout(jDialog1.getContentPane());
        
jDialog1.getContentPane().setLayout(jDialog1Layout);
        
jDialog1Layout.setHorizontalGroup(
            
jDialog1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .
add(0400Short.MAX_VALUE)
        );
        
jDialog1Layout.setVerticalGroup(
            
jDialog1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .
add(0300Short.MAX_VALUE)
        );

        
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        
setBackground(javax.swing.UIManager.getDefaults().getColor("close_button_border_focus"));
        
setForeground(new java.awt.Color(255153102));
        
setResizable(false);
        
jLabel1.setFont(new java.awt.Font("MS Sans Serif"114));
        
jLabel1.setText("B\u00fasqueda por :");

        
m1_71.setSelected(true);
        
m1_71.setText("Tarifa 71");
        
m1_71.setBorder(javax.swing.BorderFactory.createEmptyBorder(0000));
        
m1_71.setMargin(new java.awt.Insets(0000));
        
m1_71.addActionListener(new java.awt.event.ActionListener() {
            public 
void actionPerformed(java.awt.event.ActionEvent evt) {
                
m1_71ActionPerformed(evt);
            }
        });

        
m1_64.setText("Tarifa 64");
        
m1_64.setBorder(javax.swing.BorderFactory.createEmptyBorder(0000));
        
m1_64.setMargin(new java.awt.Insets(0000));
        
m1_64.addActionListener(new java.awt.event.ActionListener() {
            public 
void actionPerformed(java.awt.event.ActionEvent evt) {
                
m1_64ActionPerformed(evt);
            }
        });

        
jButton1.setText("Buscar...");
        
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public 
void mouseClicked(java.awt.event.MouseEvent evt) {
                
jButton1MouseClicked(evt);
            }
        });

        
jLabel2.setFont(new java.awt.Font("MS Sans Serif"114));
        
jLabel2.setText("Modificar:");

        
m2_71.setText("Tarifa 71");
        
m2_71.setBorder(javax.swing.BorderFactory.createEmptyBorder(0000));
        
m2_71.setMargin(new java.awt.Insets(0000));
        
m2_71.addActionListener(new java.awt.event.ActionListener() {
            public 
void actionPerformed(java.awt.event.ActionEvent evt) {
                
m2_71ActionPerformed(evt);
            }
        });

        
m2_64.setText("Tarifa 64");
        
m2_64.setBorder(javax.swing.BorderFactory.createEmptyBorder(0000));
        
m2_64.setMargin(new java.awt.Insets(0000));
        
m2_64.addActionListener(new java.awt.event.ActionListener() {
            public 
void actionPerformed(java.awt.event.ActionEvent evt) {
                
m2_64ActionPerformed(evt);
            }
        });

        
jButton2.setText("Modificar..");

        
jLabel3.setFont(new java.awt.Font("MS Sans Serif"114));
        
jLabel3.setText("Agregar:");

        
m3_71.setText("Tarifa 71");
        
m3_71.setBorder(javax.swing.BorderFactory.createEmptyBorder(0000));
        
m3_71.setMargin(new java.awt.Insets(0000));
        
m3_71.addActionListener(new java.awt.event.ActionListener() {
            public 
void actionPerformed(java.awt.event.ActionEvent evt) {
                
m3_71ActionPerformed(evt);
            }
        });

        
m3_64.setText("Tarifa 64");
        
m3_64.setBorder(javax.swing.BorderFactory.createEmptyBorder(0000));
        
m3_64.setMargin(new java.awt.Insets(0000));
        
m3_64.addActionListener(new java.awt.event.ActionListener() {
            public 
void actionPerformed(java.awt.event.ActionEvent evt) {
                
m3_64ActionPerformed(evt);
            }
        });

        
jButton3.setText("Agregar...");

        
jLabel4.setFont(new java.awt.Font("MS Sans Serif"124));
        
jLabel4.setForeground(new java.awt.Color(0153102));
        
jLabel4.setText("M  E  D  I  C  I  \u00d3  N ");

        
jLabel5.setFont(new java.awt.Font("MS Sans Serif"314));
        
jLabel5.setForeground(new java.awt.Color(0102102));
        
jLabel5.setText("Pruebas");

        
la.setText("}");

        
l.setText("bueno");

                       

    private 
void jButton1MouseClicked(java.awt.event.MouseEvent evt) {                                      
// TODO add your handling code here:
       
m1_64.setText("skk");
        
busqueda bs= new busqueda();
          
       
bs.setVisible(true);
          
          
          
       
        
    }                                     

            
    
    
/**
     * @param args the command line arguments
     */
    
    
public void inic(){
    
ButtonGroup group = new ButtonGroup();
    
group.add(m1_71);
    
group.add(m1_64);
    
group.add(m2_71);
    
group.add(m2_64);
    
group.add(m3_71);
    
group.add(m3_64);
 
  
    
m1_64.addChangeListener(new javax.swing.event.ChangeListener() {

      public 
void stateChanged(ChangeEvent e) {
       
          
m1_64_stateChanged(e);
         
      }
    });

    }
   
    public  
void m1_64_actionPerfomed(ActionEvent e){
        
String factoryName=null;        
        
l.setText("s");
              
        if (
e.getActionCommand() == "Tarifa 64") {
            
l.setVisible(true);
            
l.setText("siiii");
        } else {
           
l.setVisible(true);
            
l.setText("hola");
        }
   }
  
    
    
    
    
       
   public  
void m1_64_stateChanged(ChangeEvent e){
   
   
     
int i=0
     if (
m1_64.isSelected()){
           
           
la.setVisible(true);
           
la.setText("prueba"+i);
           
i++;       
         
      }
     else{
        
la.setVisible(false);
      }
   
    }


     
    
        public static 
void main(String args[]) {
            
java.awt.EventQueue.invokeLater(new Runnable() {
                public 
void run() {
                    new 
principal().setVisible(true);
                
            }
        });
    }
    
   

__________________
-URL= Go PHP5.
-Age=22.
-Learning=PHP,J2EE,Struts,MAMBO,C++,JSON,AJAX,XHTML ,CSS.
  #6 (permalink)  
Antiguo 30/10/2006, 12:23
Avatar de B**
B**
 
Fecha de Ingreso: enero-2006
Ubicación: Monterrey,Mexico
Mensajes: 952
Antigüedad: 18 años, 3 meses
Puntos: 3
Y el codigo q genera netbeans:
Código PHP:
 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(org.jdesktop.layout.GroupLayout.DEFAULT_SIZEShort.MAX_VALUE)
                .
add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .
add(org.jdesktop.layout.GroupLayout.TRAILINGlayout.createSequentialGroup()
                        .
add(jLabel5)
                        .
add(244244244))
                    .
add(org.jdesktop.layout.GroupLayout.TRAILINGlayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .
add(layout.createSequentialGroup()
                            .
add(404040)
                            .
add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILINGfalse)
                                .
add(org.jdesktop.layout.GroupLayout.LEADINGlayout.createSequentialGroup()
                                    .
add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .
add(jLabel1)
                                        .
add(m1_64)
                                        .
add(m1_71)
                                        .
add(jButton1))
                                    .
addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATEDorg.jdesktop.layout.GroupLayout.DEFAULT_SIZEShort.MAX_VALUE)
                                    .
add(laorg.jdesktop.layout.GroupLayout.PREFERRED_SIZE96org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .
add(464646)
                                    .
add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .
add(layout.createSequentialGroup()
                                            .
add(171717)
                                            .
add(jButton2))
                                        .
add(m2_64)
                                        .
add(m2_71)
                                        .
add(jLabel2)))
                                .
add(org.jdesktop.layout.GroupLayout.LEADINGlayout.createSequentialGroup()
                                    .
add(198198198)
                                    .
add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADINGfalse)
                                        .
add(layout.createSequentialGroup()
                                            .
add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                                .
add(m3_64)
                                                .
add(m3_71)
                                                .
add(jLabel3)
                                                .
add(jButton3))
                                            .
addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED))
                                        .
add(layout.createSequentialGroup()
                                            .
add(jLabel6)
                                            .
addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATEDorg.jdesktop.layout.GroupLayout.DEFAULT_SIZEShort.MAX_VALUE)
                                            .
add(l)
                                            .
add(219219219)))))
                            .
add(166166166))
                        .
add(org.jdesktop.layout.GroupLayout.TRAILINGlayout.createSequentialGroup()
                            .
add(jLabel4)
                            .
add(203203203)))))
        );
        
layout.setVerticalGroup(
            
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .
add(layout.createSequentialGroup()
                .
addContainerGap()
                .
add(jLabel4org.jdesktop.layout.GroupLayout.PREFERRED_SIZE32org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .
addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .
add(jLabel5)
                .
add(353535)
                .
add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .
add(layout.createSequentialGroup()
                        .
add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .
add(jLabel2)
                            .
add(jLabel1))
                        .
addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .
add(m1_71)
                        .
addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .
add(m1_64))
                    .
add(layout.createSequentialGroup()
                        .
add(262626)
                        .
add(m2_71)
                        .
addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .
add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .
add(m2_64)
                            .
add(la))))
                .
add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADINGfalse)
                    .
add(layout.createSequentialGroup()
                        .
addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .
add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .
add(jButton1)
                            .
add(jButton2))
                        .
add(393939))
                    .
add(org.jdesktop.layout.GroupLayout.TRAILINGlayout.createSequentialGroup()
                        .
addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATEDorg.jdesktop.layout.GroupLayout.DEFAULT_SIZEShort.MAX_VALUE)
                        .
add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .
add(jLabel6)
                            .
add(l))
                        .
add(242424)))
                .
add(jLabel3)
                .
addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .
add(m3_71)
                .
addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .
add(m3_64)
                .
addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .
add(jButton3)
                .
addContainerGap(59Short.MAX_VALUE))
        );
        
pack();
    }
// </editor-fold> 
__________________
-URL= Go PHP5.
-Age=22.
-Learning=PHP,J2EE,Struts,MAMBO,C++,JSON,AJAX,XHTML ,CSS.
  #7 (permalink)  
Antiguo 30/10/2006, 12:29
Avatar de chuidiang
Colaborador
 
Fecha de Ingreso: octubre-2004
Mensajes: 3.774
Antigüedad: 19 años, 7 meses
Puntos: 454
Hola:

En el primer trozo de código veo un

setDefaultCloseOperation (WindowConstants.EXIT_ON_CLOSE);

eso lo que hace System.exit() y lo mata todo. Cambialo pon un HIDE_ON_CLOSE o DISPOSE_ON_CLOSE, según quieras sólo ocultar la ventana (para usarla más adelante) o destruirla definitivamente.

Se bueno.
__________________
Apuntes Java
Wiki de Programación
  #8 (permalink)  
Antiguo 30/10/2006, 14:12
 
Fecha de Ingreso: octubre-2003
Mensajes: 3.578
Antigüedad: 20 años, 6 meses
Puntos: 51
Eso mismo . Esas son las cosas por las que es bueno aprender a hacer las cosas "a mano" antes de fiarse de los IDEs. Luego te la juegan .
  #9 (permalink)  
Antiguo 30/10/2006, 17:27
Avatar de B**
B**
 
Fecha de Ingreso: enero-2006
Ubicación: Monterrey,Mexico
Mensajes: 952
Antigüedad: 18 años, 3 meses
Puntos: 3
Ok.. gracias a los 2 por su ayuda..
__________________
-URL= Go PHP5.
-Age=22.
-Learning=PHP,J2EE,Struts,MAMBO,C++,JSON,AJAX,XHTML ,CSS.
  #10 (permalink)  
Antiguo 30/10/2006, 20:30
Avatar de stock  
Fecha de Ingreso: junio-2004
Ubicación: Monterrey NL
Mensajes: 2.390
Antigüedad: 19 años, 10 meses
Puntos: 53
Cita:
Iniciado por GreenEyed Ver Mensaje
...por las que es bueno aprender a hacer las cosas "a mano" antes de fiarse de los IDEs. Luego te la juegan .

es lo que siempre digo yo!! no hay nada como saber escribir las cosas por uno mismo

have funnnnnnnnnn
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:05.