Tela de login fica por tras de outro frame

5 respostas
C

Pessoal gostaria de um auxílio....

Eu estou tentando criar uma tela de login(que já esta sendo um problemão) então o que eu fiz nesta tela foi apenas fazer um botão que ao clicado chama a tela principal onde eu tenho os meus menus.. O problema é que a tela de login fica por trás e eu não consigo de jeito nenhum fechá-la... vocês poderiam me ajudar? abaixo está o código da tela de login, da main e da principal... Obrigado!!!

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package zooftware;

/**
 *
 * @author CarlosTatiVivi
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        
        new LoginZooftware().setVisible(true);
        
        
        
    }

}
/*
 * LoginZooftware.java
 *
 * Created on 16 de Março de 2009, 11:09
 */

package zooftware;



/**
 *
 * @author  CarlosTatiVivi
 */
public class LoginZooftware extends javax.swing.JFrame {

    /** Creates new form LoginZooftware */
    public LoginZooftware() {
        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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("ZOOFTWARE Log On: versão 1.0");

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zooftware/Login.png"))); // NOI18N
        jButton1.setText("ENTRAR NO SISTEMA");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(56, 56, 56)
                .addComponent(jButton1)
                .addContainerGap(75, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton1)
                .addContainerGap(39, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 122, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

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

new Principal().setVisible(true);
//new LoginZooftware().setEnabled(false);
//this.setFocusableWindowState(true);
}                                        

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                
                
                
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration                   

}
/*
 * Principal.java
 *
 * Created on 23 de Fevereiro de 2009, 10:52
 */

package zooftware;

/**
 *
 * @author  CarlosTatiVivi
 */
public class Principal extends javax.swing.JFrame {

    /** Creates new form Principal */
    public Principal() {
        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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        mnuCadastro = new javax.swing.JMenu();
        mnuAnimal = new javax.swing.JMenuItem();
        jMenuItemGruposDeAnimais = new javax.swing.JMenuItem();
        jMenuItemBiologos = new javax.swing.JMenuItem();
        jMenuItemEmpresa = new javax.swing.JMenuItem();
        jMenuItemRegistrarFornecedor = new javax.swing.JMenuItem();
        jMenuItemRegistrarFuncionarios = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenu1 = new javax.swing.JMenu();
        jMenu3 = new javax.swing.JMenu();
        jMenu4 = new javax.swing.JMenu();
        mnuSair = new javax.swing.JMenu();
        jSeparator1 = new javax.swing.JSeparator();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zooftware/LOGO_ZOOFTWARE_1.jpg"))); // NOI18N
        jLabel1.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentHidden(java.awt.event.ComponentEvent evt) {
                jLabel1ComponentHidden(evt);
            }
        });

        mnuCadastro.setText("Cadastro");
        mnuCadastro.setToolTipText("Utilize este menu para realizar registros de informações do banco de dados. ");
        mnuCadastro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuCadastroActionPerformed(evt);
            }
        });

        mnuAnimal.setText("Registrar Animal");
        mnuAnimal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuAnimalActionPerformed(evt);
            }
        });
        mnuCadastro.add(mnuAnimal);

        jMenuItemGruposDeAnimais.setText("Registrar Grupos de Animais");
        jMenuItemGruposDeAnimais.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemGruposDeAnimaisActionPerformed(evt);
            }
        });
        mnuCadastro.add(jMenuItemGruposDeAnimais);

        jMenuItemBiologos.setText("Registrar Biólogos");
        jMenuItemBiologos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemBiologosActionPerformed(evt);
            }
        });
        mnuCadastro.add(jMenuItemBiologos);

        jMenuItemEmpresa.setText("Registrar Empresa");
        jMenuItemEmpresa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemEmpresaActionPerformed(evt);
            }
        });
        mnuCadastro.add(jMenuItemEmpresa);

        jMenuItemRegistrarFornecedor.setText("Registrar Fornecedor");
        jMenuItemRegistrarFornecedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemRegistrarFornecedorActionPerformed(evt);
            }
        });
        mnuCadastro.add(jMenuItemRegistrarFornecedor);

        jMenuItemRegistrarFuncionarios.setText("Registrar Funcionário");
        jMenuItemRegistrarFuncionarios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemRegistrarFuncionariosActionPerformed(evt);
            }
        });
        mnuCadastro.add(jMenuItemRegistrarFuncionarios);

        jMenuBar1.add(mnuCadastro);

        jMenu2.setText("Consultas");
        jMenu2.setToolTipText("Utilize este menu para geração de relatórios.");
        jMenuBar1.add(jMenu2);

        jMenu1.setText("Outros");
        jMenuBar1.add(jMenu1);

        jMenu3.setText("Ajuda");
        jMenuBar1.add(jMenu3);

        jMenu4.setText("Sobre");
        jMenuBar1.add(jMenu4);

        mnuSair.setText("Sair");
        mnuSair.setToolTipText("Clique aqui para sair do programa.");
        mnuSair.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mnuSairMouseClicked(evt);
            }
        });
        mnuSair.add(jSeparator1);

        jMenuBar1.add(mnuSair);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                        

private void mnuSairMouseClicked(java.awt.event.MouseEvent evt) {                                     
System.exit(0);
}                                    

private void mnuAnimalActionPerformed(java.awt.event.ActionEvent evt) {                                          
new RegistrarAnimal().setVisible(true);
}                                         

private void jMenuItemGruposDeAnimaisActionPerformed(java.awt.event.ActionEvent evt) {                                                         
new RegistrarGruposDeAnimais().setVisible(true);
    
}                                                        

private void mnuCadastroActionPerformed(java.awt.event.ActionEvent evt) {                                            
// TODO add your handling code here:
}                                           

private void jMenuItemBiologosActionPerformed(java.awt.event.ActionEvent evt) {                                                  
new RegistrarBiologos().setVisible(true);

}                                                 

private void jMenuItemEmpresaActionPerformed(java.awt.event.ActionEvent evt) {                                                 
new RegistrarEmpresa().setVisible(true);
}                                                

private void jMenuItemRegistrarFuncionariosActionPerformed(java.awt.event.ActionEvent evt) {                                                               
new RegistrarFuncionarios().setVisible(true);
}                                                              

private void jMenuItemRegistrarFornecedorActionPerformed(java.awt.event.ActionEvent evt) {                                                             
new RegistrarFornecedores().setVisible(true);
}                                                            

private void jLabel1ComponentHidden(java.awt.event.ComponentEvent evt) {                                        
// 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 Principal().setVisible(false);
               // new LoginZooftware().setVisible(false);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItemBiologos;
    private javax.swing.JMenuItem jMenuItemEmpresa;
    private javax.swing.JMenuItem jMenuItemGruposDeAnimais;
    private javax.swing.JMenuItem jMenuItemRegistrarFornecedor;
    private javax.swing.JMenuItem jMenuItemRegistrarFuncionarios;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JMenuItem mnuAnimal;
    private javax.swing.JMenu mnuCadastro;
    private javax.swing.JMenu mnuSair;
    // End of variables declaration                   

}

5 Respostas

julianofischer

Serve essa solução?

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
   
 new Principal().setVisible(true);
  
 this.setVisible(false);

 //new LoginZooftware().setEnabled(false);  
 //this.setFocusableWindowState(true);  
 }
C

Poxa cara… era algo super simples…deu certo sim. Muito obrigado pela ajuda…Valeu mesmo… Um abraço…

julianofischer

Bom estudo aí pra você.

colored

Mas setviible(false) ele apenas esconde,
usa NomedoFrame.dispose()

que ele fecha o frame que vc ker

berg.pb

não precisa colocar o nome do frame…
a questão é: vc vai precisar deste frame de novo?

//caso vc precise, esconde
this.setVisible(false);

//caso vc não precise, destroi ele.
this.dispose();

Abraços

Criado 17 de março de 2009
Ultima resposta 20 de mar. de 2009
Respostas 5
Participantes 4