Não consigo fechar meu splash e agora?

14 respostas
L

Por favor pessoal, não consigo fazer meu splash sair, me ajude!

package loading;

import Telas.Login;
import Telas.Principal;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JProgressBar;

public class SplashJProgressBar extends javax.swing.JWindow {
    private JLabel jLabelSplashImage;
    private JLabel jLabelTextoCarregamento;
    private static JLabel jLabelTextoDinamicoPlugins;
    private static JProgressBar jProgressBarSistema;
    
    public SplashJProgressBar() {
        criandoComponentes();
        this.setVisible(true);
    }

private void criandoComponentes() {
        /**
         * Inicializando as variavaeis utilizadas
         */
        jProgressBarSistema = new JProgressBar();
        jLabelSplashImage = new JLabel();
        jLabelTextoCarregamento = new JLabel();
        jLabelTextoDinamicoPlugins = new JLabel();
        /**
         * Carregando a imagem do Splash e adicionando a imagem ao componente
         * jLabelSplashImage
         */
        ImageIcon imageIcon = new ImageIcon(getClass().getResource("loadingtela.png"));
        jLabelSplashImage.setIcon(imageIcon);
        /**
         * Definindo dinamicamente o tamando do container segundo o tamanho da imagem.
         */
        this.setMinimumSize(new java.awt.Dimension(imageIcon.getIconWidth(),imageIcon.getIconHeight()));
        jLabelSplashImage.setBounds(0, 0, imageIcon.getIconWidth(), imageIcon.getIconHeight());
        /**
         * A definicao do layout=null e importante para possibilitar que os componentes
         * fiquem sobrescritros em tempo de execucao
         */
        getContentPane().setLayout(null);
        /**
         * Definindo a localizacao do splash no centro da tela
         */
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        this.setLocation((screen.width - this.getSize().width) / 2, (screen.height - this.getSize().height) / 2);

        /**
         * Setando parametros da variavel jProgressBarSistema
         */
        jProgressBarSistema.setForeground(new Color(0,0,0));
        jProgressBarSistema.setPreferredSize(new java.awt.Dimension(900, 6));
        jProgressBarSistema.setBounds(0, 342, imageIcon.getIconWidth(), 9);
        jProgressBarSistema.setBorderPainted(false);
        jProgressBarSistema.setIndeterminate(true);
        /**
         * Adicionando o jProgressBarSistema a classe SplashJProgressBar
         */
        getContentPane().add(jProgressBarSistema);
        
        /**
         * Setando parametros da variavel jProgressBarSistema
         */
        jLabelTextoCarregamento.setForeground(new java.awt.Color(0,0,0));
        jLabelTextoCarregamento.setFont(new java.awt.Font("DialogInput", 0, 11));
        jLabelTextoCarregamento.setText("Carregando...");
        jLabelTextoCarregamento.setBounds(250, 345, 120, 30);
        /**
         * Adicionando o jProgressBarSistema a classe SplashJProgressBar
         */
        this.getContentPane().add(jLabelTextoCarregamento);
      
        /**
         * Setando parametros da variavel jProgressBarSistema
         */
        jLabelTextoDinamicoPlugins.setForeground(new java.awt.Color(0,0,0));
        jLabelTextoDinamicoPlugins.setFont(new java.awt.Font("DialogInput", 0, 11));
        jLabelTextoDinamicoPlugins.setBounds(360, 345, 230, 30);
        /**
         * Adicionando o jProgressBarSistema a classe SplashJProgressBar
         */
        this.getContentPane().add(jLabelTextoDinamicoPlugins);
        
        /**
         * O Ultimo item adicionado no conteiner deve ser o componente que comtem 
         * a imagem do Splah
         */
        this.getContentPane().add(jLabelSplashImage);
        this.pack();

    }

    public static void main(String args[]) {
       
            new SplashJProgressBar();
            
            /**
             * Rotina para exibicao de um texto qualquer no carregamento do seu 
             * sistema
             */
            int i=100;
                for (int j = 1; j <= 10000; j++) {
                   
                         if(j==(10000/i)){
                             
                             jLabelTextoDinamicoPlugins.setText("Contador para executar: " + i + "%");
                             i--;
                              try{
                        Thread.sleep(250);
                    }catch(Exception e){
                        
                    }
                             
                         }

                 }
             //chamei a tela de login, mas agora preciso fechar o splash!
            new Login().show();

    }
   
}

14 Respostas

RiQuInHo_

na verdade vc copiou esse codigo…

teria que fazer um comando que dê exit quando acabar sua tread.chegar 100% e tipo uma jogada “False”

eliangela

Fecha seu splash antes de chamar a tela de Login, assim:

//resto dos codigos aqui
splash.dispose();
new Login().show();
zicky23

o meu ta assim

new Autenticacao().setVisible(true);
                
                Splash.this.dispose();

abre o novo frame e fecha o splash

L

RiQuInHo_$_$:
na verdade vc copiou esse codigo…

teria que fazer um comando que dê exit quando acabar sua tread.chegar 100% e tipo uma jogada “False”

não copie fui olhando o tutorial da guj, que por sinal são muito bons…!!

Mas c eu der exit vai fechar o programa, mas não quero fechar o programa, quero fechar o splash!

L

Não funciono nada!

zicky23

o meu splash ta assim, tenta ai...

package grafica;

import db.ConexaoDB;
import java.awt.Dimension;
import java.net.ServerSocket;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
import javax.swing.JWindow;
import org.netbeans.lib.awtextra.AbsoluteConstraints;
import org.netbeans.lib.awtextra.AbsoluteLayout;

public class Splash extends JWindow{
    private static ServerSocket s;
    AbsoluteLayout Absoluto;
    AbsoluteConstraints absimage, AbsBarra,AbsLabel,AbsDate;
    ImageIcon image;
    JLabel jlabel,jLabel1,jLabelDate;
    JProgressBar barra;
    Integer value;
    Float versao;
    Date dataupdate;
    ConexaoDB obj_conexao = new ConexaoDB();
    public Splash(){
        try { // aki nao permite que se abra mais de uma instancia do software por vez nesta maquina
            s = new ServerSocket(9581);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Desculpe, mas só uma aplicação pode ser executada por vez.");
            System.exit(0);
        }
        obj_conexao.conecta(); // conecta o db
        Autent();
        SelectVersao();
        Absoluto = new AbsoluteLayout();
        absimage = new AbsoluteConstraints(0, 0);
        AbsBarra = new AbsoluteConstraints(14,9);
        AbsLabel = new AbsoluteConstraints(300,40);
        AbsDate = new AbsoluteConstraints(300,60);
        jLabel1 = new JLabel();
        jlabel = new JLabel();
        jLabelDate = new JLabel();
        barra = new JProgressBar();
        barra.setPreferredSize(new Dimension(200,15));
        this.getContentPane().setLayout(Absoluto);
        image = new ImageIcon(this.getClass().getResource("logoGesObras2.png"));
        jlabel.setIcon(image);
        jLabel1.setText("Versão: "+versao);
        jLabelDate.setText(""+new SimpleDateFormat("dd/MM/yyyy").format(dataupdate));
        this.getContentPane().add(jLabel1,AbsLabel);
        this.getContentPane().add(jLabelDate,AbsDate);
        this.getContentPane().add(jlabel,absimage);
        this.getContentPane().add(barra,AbsBarra);
        new Thread(){
            public void run(){
                int i=0;
                while(i<101){
                    barra.setValue(i);
                    i++;
                    try{
                        sleep(50);
                    } catch (InterruptedException ex){
                        Logger.getLogger(Splash.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
                //System.exit(0);

                new Autenticacao(null).setVisible(true); //AKI ABRE O SEU JFRAME 
                Splash.this.dispose(); AKI FECHA ESSE SPLASH
            }
        }.start();
        this.pack();
        this.setVisible(true);
        this.setLocationRelativeTo(null);
    }
    
    public static void main(String args[]){
        new Splash();
    }

}
L
zicky23:
o meu splash ta assim, tenta ai...
package grafica;

import db.ConexaoDB;
import java.awt.Dimension;
import java.net.ServerSocket;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
import javax.swing.JWindow;
import org.netbeans.lib.awtextra.AbsoluteConstraints;
import org.netbeans.lib.awtextra.AbsoluteLayout;

public class Splash extends JWindow{
    private static ServerSocket s;
    AbsoluteLayout Absoluto;
    AbsoluteConstraints absimage, AbsBarra,AbsLabel,AbsDate;
    ImageIcon image;
    JLabel jlabel,jLabel1,jLabelDate;
    JProgressBar barra;
    Integer value;
    Float versao;
    Date dataupdate;
    ConexaoDB obj_conexao = new ConexaoDB();
    public Splash(){
        try { // aki nao permite que se abra mais de uma instancia do software por vez nesta maquina
            s = new ServerSocket(9581);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Desculpe, mas só uma aplicação pode ser executada por vez.");
            System.exit(0);
        }
        obj_conexao.conecta(); // conecta o db
        Autent();
        SelectVersao();
        Absoluto = new AbsoluteLayout();
        absimage = new AbsoluteConstraints(0, 0);
        AbsBarra = new AbsoluteConstraints(14,9);
        AbsLabel = new AbsoluteConstraints(300,40);
        AbsDate = new AbsoluteConstraints(300,60);
        jLabel1 = new JLabel();
        jlabel = new JLabel();
        jLabelDate = new JLabel();
        barra = new JProgressBar();
        barra.setPreferredSize(new Dimension(200,15));
        this.getContentPane().setLayout(Absoluto);
        image = new ImageIcon(this.getClass().getResource("logoGesObras2.png"));
        jlabel.setIcon(image);
        jLabel1.setText("Versão: "+versao);
        jLabelDate.setText(""+new SimpleDateFormat("dd/MM/yyyy").format(dataupdate));
        this.getContentPane().add(jLabel1,AbsLabel);
        this.getContentPane().add(jLabelDate,AbsDate);
        this.getContentPane().add(jlabel,absimage);
        this.getContentPane().add(barra,AbsBarra);
        new Thread(){
            public void run(){
                int i=0;
                while(i<101){
                    barra.setValue(i);
                    i++;
                    try{
                        sleep(50);
                    } catch (InterruptedException ex){
                        Logger.getLogger(Splash.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
                //System.exit(0);

                new Autenticacao(null).setVisible(true); //AKI ABRE O SEU JFRAME 
                Splash.this.dispose(); AKI FECHA ESSE SPLASH
            }
        }.start();
        this.pack();
        this.setVisible(true);
        this.setLocationRelativeTo(null);
    }
    
    public static void main(String args[]){
        new Splash();
    }

}

nada =/!

zicky23

tenta limpar e construir novamente a aplicação pode ser algum erro.

valeu

RiQuInHo_

vou te mandar um exemplo veja, guenta ai 8)

RiQuInHo_

vê se da certo?

L

RiQuInHo_$_$:
vê se da certo?

amigo isso eu já tinha feito!

agora o negocio é o seguinte… como faço para quando terminar de carregar, abrir minha nova tela e fechar a splash!

RiQuInHo_

olha com eu faço no meu projeto

public class Main
{
  private SplashJProgressBar splash;

  public Main()
  {
    Runnable executa = new MyRunnable();

    Thread tarefa = new Thread(executa);
    tarefa.start();
  }

  public static void main(String[] args)
  {
    Main m = new Main();
  }

  class MyRunnable
    implements Runnable
  {
    public void run()
    {
      Main.this.splash = new SplashJProgressBar();

      for (int i = 1; i <= 100; ++i) {
        try
        {
          Thread.sleep(100L);

          SplashJProgressBar.getJLabelTextoDinamicoPlugins().setText("Exibição da tela de Cadastro:" + i);
        }
        catch (Exception e) {
          System.out.println("Erro na thread");
        }

      }

      Main.this.splash.setVisible(false); // aqui ele some
      new LoginBl().setVisible(true);  // aqui eu chamo minha tela de login 
    }
  }
}
InicianteJavaHenriqu

Tbm já tentei implementar está Splash Screen do GUJ e não consegui :wink: , mas segue uma que foi postada pelo rmenezzes e funciona:

:arrow: http://www.guj.com.br/java/85565-splash-screen-com-jprogressbar-exemplo-funcional

:thumbup:

eliangela

Eu faço a minha Splash assim:

public static void main(String[] args) {
		final SplashScreen sp = new SplashScreen("img/logo-512.png"); //é minha classe para o Splash... Splash extends JFrame...
		sp.setVisible(true);

		SwingUtilities.invokeLater(new Runnable() {

			@Override
			public void run() {
				try {
					UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
					FramePrincipal fPrincipal = new FramePrincipal();
					fPrincipal.setVisible(true);
					sp.dispose();
				} catch (Exception e) {
				}
			}
		});
	}

Se eu não me engano, se vc for usar um JDialog pra isso, vc tem que colocar a SplashScreen numa Thread separada.

Criado 24 de abril de 2012
Ultima resposta 25 de abr. de 2012
Respostas 14
Participantes 5