Criando uma Splash

5 respostas
L

OBS: ANTES VÁ A BIBLIOTECA E ADICIONA O (Layout absoluto), e pronto.

//MAIN splash!


import java.awt.Dimension;
import java.awt.Image;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
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 
{
    AbsoluteLayout absoluto;
    AbsoluteConstraints absimage, absbarra;
    ImageIcon image;
    JLabel jlabel;
    JProgressBar barra;
    
    public splash()
    {
    absoluto = new AbsoluteLayout();
    absimage = new AbsoluteConstraints(0,0);
    //(0,0) indica o tamanho das imagens, veja no windows o tamanho dela e coloque ai nas proporções.
    absbarra = new AbsoluteConstraints(0,309);
    jlabel = new JLabel();
    image = new ImageIcon(this.getClass().getResource("imagem.jpg"));
    jlabel = new JLabel();

    //setando a imagem gif de loading.
    jlabel.setIcon("image.gif");
    barra = new JProgressBar();
    barra.setPreferredSize(new Dimension(0,10));
    this.getContentPane().setLayout(absoluto);
    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 (tempo em segundos para abrir - cada segundo = 60 milésimo / 50 segundos = contagem progressiva! ).
                        sleep(50);
                    } catch (InterruptedException ex) 
                    {
                        Logger.getLogger(splash.class.getName()).log(Level.SEVERE, null, ex);
                    }     
            }
           //Tela que queira chamar.
           new CalculadoraTELA().show();
         }
    
    }.start();
    this.pack();
    this.setVisible(true);
    /*Setando o local da tela a ser aberto:
      sendo: "this.setLocationRelativeTo(null);" o null indica o centro!*/
     this.setLocationRelativeTo(null);
    
    AbsoluteConstraints absimage, absbarra;
    
    }
    public static void main(String args[]){
        //abrindo a imagem de boas vindas - sobe no metodos acima^.
        new splash();
        //apos feito os metodos, ele vem para essa nova chamada, e fecha a imagem de boas vindas.
        new splash().dispose();
    
    }
}

}

5 Respostas

drsmachado

Java 6 especifica splash no manifest.mf

L

Uhmmm?

drsmachado
L

drsmachado:
http://docs.oracle.com/javase/tutorial/uiswing/misc/splashscreen.html:

How to Use a JAR File to Display Splash Screen

If your application is packaged in a JAR file, you can use the SplashScreen-Image option in a manifest file to show a splash screen. Place the image in the JAR file and specify the path in the option as follows:

Manifest-Version: 1.0
Main-Class:
SplashScreen-Image:

Try this:

Compile the SplashDemo.java file.
Save the splash.gif image in the images directory.
Prepare the splashmanifest.mf file as follows:

Manifest-Version: 1.0
Main-Class: SplashDemo
SplashScreen-Image: images/splash.gif

Create a JAR file using the following command:

jar cmf splashmanifest.mf splashDemo.jar SplashDemo*.class images/splash.gif

For more information about JAR files, see Using JAR Files in the Packaging Programs in JAR Files page.
Run the application:

java -jar splashDemo.jar

Wait until the splash screen has been completly displayed.
The application window appears. To close the window choose File|Exit from the pop-up menu or click the X.

Ahhh sim… mas o código que mostrei acima, ele carrega de 0 à 101%, e mostra a barra de loading.

zicky23
segue um splash
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);

                if(value == 1){
                    new Autenticacao("PADRAO").setVisible(true);
                }else{
                    new Autenticacao(null).setVisible(true);
                }
                Splash.this.dispose();
            }
        }.start();
        this.pack();
        this.setVisible(true);
        this.setLocationRelativeTo(null);
    }
    
    public static void main(String args[]){
        new Splash();
    }


}
Criado 22 de abril de 2012
Ultima resposta 24 de abr. de 2012
Respostas 5
Participantes 3