Splash Screen!!!
Publicado por Rogério M. de Queiroz 02/03/2007
[ Hits: 9.682 ]
Homepage: www.dataview.com.br / www.agilecti.com.br
Para quem gosta de apresentações rápidas (Splash Screen) no carregamento de suas aplicações java, esse exemplo é uma boa.
/*======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!
Algoritmo para Gerar um Sudoku NxN válido
Algoritmos para Teoria dos Números
Imagem de Background atravez de um JDesktopPane
IA Turbina o Desktop Linux enquanto distros renovam forças
Como extrair chaves TOTP 2FA a partir de QRCODE (Google Authenticator)
Linux em 2025: Segurança prática para o usuário
Desktop Linux em alta: novos apps, distros e privacidade marcam o sábado
Atualizando o Fedora 42 para 43
Como saber se o seu e-mail já teve a senha vazada?
Como descobrir se a sua senha já foi vazada na internet?
E aí? O Warsaw já está funcionando no Debian 13? [RESOLVIDO] (15)
Secure boot, artigo interessante, nada técnico. (4)
copiar library para diretorio /usr/share/..... su com Falha na a... (1)









