Janela Splash

0 respostas
shadowdf

Boa noite,

estou entrando nesse mundo chamado java e estou cheio de dúvidas. :smiley:

mas a principio, estou começando a fazer um programinha de locadora para aprender a programar em java, e estava em duvida de como eu faço a minha class splash fazer uma conexão com a minha classe conexão_banco de dados e chamar e testar a conexão para executar e exibir na tela splash.

Essa é minha tela splash (Descupla o lixo é por que eu estou fazendo em netbeans JFrame)

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

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author michael
 */
public class Splash extends javax.swing.JFrame {

    /**
     * Creates new form Splash
     */
    public Splash() {
        initComponents();
     
        new Thread(){
            
            public void run(){
                
                for(int i=0; i<=100;i++){
                    try {
                        sleep(60);
                        jProgressBar1.setValue(i);
                        
                        if(jProgressBar1.getValue() <=20)
                        {                            
                            jLabel5.setText("Carregando Banco de Dados");
                        }
                        else if(jProgressBar1.getValue() <=40)
                        {
                            jLabel5.setText("Carregando Tabelas");
                        }
                        else if(jProgressBar1.getValue() <= 95)
                        {
                            jLabel5.setText("Carregado Sistema");
                        }
                        else {
                            jLabel5.setText("Carregado com Sucesso");
                                                   
                        }
                        
                    } catch (InterruptedException ex) {
                        Logger.getLogger(Splash.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    
                }
                
                new Login().setVisible(true);
                Splash.this.dispose();    
                
            }
            
        }.start();
        
    }

    /**
     * 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();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jProgressBar1 = new javax.swing.JProgressBar();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(255, 255, 255));
        setForeground(java.awt.Color.white);
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("System Loc - Sistema de Locação");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(4, 10, 440, -1));

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Login/Splash2.png"))); // NOI18N
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 35, -1, 144));

        jLabel3.setText("Versão: 1.0.0");
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(257, 185, -1, -1));

        jLabel4.setFont(new java.awt.Font("Dialog", 1, 8)); // NOI18N
        jLabel4.setText("Produzido por TopInfor Informatica");
        getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(257, 206, -1, -1));

        jProgressBar1.setFont(new java.awt.Font("Dialog", 0, 8)); // NOI18N
        jProgressBar1.setStringPainted(true);
        getContentPane().add(jProgressBar1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 224, 450, -1));
        getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 200, -1, -1));

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

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Splash.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Splash.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Splash.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Splash.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Splash().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JProgressBar jProgressBar1;
    // End of variables declaration                   
}

esse é a minha classe conexão com o banco de dados

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

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author michael
 */
public class CriaConexao {

    public static Connection getConexao() throws SQLException {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            System.out.println("Conectando ao Banco de Dados");
            return DriverManager.getConnection("jdbc:mysql://localhost/sysloc_db", "root", "2010cleide");
        } catch (ClassNotFoundException e) {
            throw new SQLException(e.getMessage());
        }
    }
}
Criado 16 de junho de 2013
Respostas 0
Participantes 1