Splash Screen!!!

Publicado por Rogério M. de Queiroz 02/03/2007

[ Hits: 9.771 ]

Homepage: www.dataview.com.br / www.agilecti.com.br

Download SplashScreen.zip




Para quem gosta de apresentações rápidas (Splash Screen) no carregamento de suas aplicações java, esse exemplo é uma boa.

  



Esconder código-fonte

/*======Classe SplashScreen========*/

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Toolkit;
import java.lang.reflect.InvocationTargetException;

import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;

import java.awt.Graphics;
import java.awt.Font;


public class SplashScreen extends JDialog
{
   public SplashScreen()
   {
      super();
        setTitle("Spash!!!");
      setResizable(false);
      setUndecorated(true);

      JLabel label = new JLabel( TesteSplash.getIcon(false));
      getContentPane().add(label, BorderLayout.CENTER);

        /* usando o método Paint ao invez do Código abaixo
      label = new JLabel("<html>TesteSplash "+"<br>Iniciando...<p><br></html>");
      label.setHorizontalAlignment(SwingConstants.CENTER);
      getContentPane().add(label, BorderLayout.SOUTH);
        getContentPane().setBackground(Color.LIGHT_GRAY);
        */

        setSize(TesteSplash.getIcon(false).getIconWidth(), TesteSplash.getIcon(false).getIconHeight());

        int x = Toolkit.getDefaultToolkit().getScreenSize().width;
      x = x/2 - getWidth()/2;
      int y = Toolkit.getDefaultToolkit().getScreenSize().height;
      y = y/2 - getHeight()/2;

      setLocation(x, y);
      setVisible(true);
   }
    public void paint(Graphics g)
    {
     int imageX = TesteSplash.getIcon(false).getIconWidth();
     int imageY = TesteSplash.getIcon(false).getIconHeight();
     // Apenas desenha a nossa mensagem em cima da imagem
     g.drawImage(TesteSplash.getIcon(false).getImage(), 0, 0, getBackground(), this);
     g.setFont(new Font("Arial", Font.ITALIC, 26));
     g.drawString("Screen Size: " + imageX +" / " + imageY,
     (int)(imageX / 6 ), imageY - 30);
    }
   public void close()
      throws InterruptedException, InvocationTargetException
   {
      Runnable closerRunner = new Runnable()
      {
         public void run()
         {
            setVisible(false);
            dispose();
         }
      };

      SwingUtilities.invokeAndWait(closerRunner);
   }

}
/*=============Fim da Classe=========*/

*/=============Classe Para testar o SpashScreen=========*/
import java.io.File;
import java.net.URL;
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.UIManager;


public class TesteSplash
{
    public static ImageIcon getIcon(boolean small)
   {
      URL url;
      if (small) {
         url = TesteSplash.class.getResource("/image.png");
      } else url = TesteSplash.class.getResource("/image.jpg");

      if (url == null) {
         return null;
      } else return new ImageIcon(url);
   }

   public static void main(String[] args)
   {
      SplashScreen splashScreen = new SplashScreen();
      /* Todo o código a ser carregado no main deve ficar entre o inicio do splash
      e o splashScreen.close();
      */
         javax.swing.JOptionPane.showMessageDialog(null, "Splash Iniciado!!!");
       try {
         splashScreen.close();
      } catch (Exception e) {
         e.printStackTrace();
      }


}

// Viva o Linux!

Scripts recomendados

Login gráfico em java

Crivo de Eratóstenes Simples em Java

Calcula as chances de se ganhar na mega-sena.

Imagem de Background atravez de um JDesktopPane

Planilha de cálculo para multa judicial


  

Comentários
[1] Comentário enviado por jorgewagner em 06/03/2007 - 09:50h

"Arquivo zip não encontrado" arruma o link aí.

[2] Comentário enviado por Root_ em 06/03/2007 - 10:02h

n consegui enviar o arquivo .zip, pq n tava fazendo o upload do arquivo quando eu postei, mais tem ai o codigo fonte, pelo menos eu creio q esteja funcioando 99,99%.

[3] Comentário enviado por wolliton em 22/03/2007 - 21:22h

Valeu cara gostei... hehe
sera usando no meu proximo programa.


Contribuir com comentário