Splash Screen!!!
Publicado por Rogério M. de Queiroz 02/03/2007
[ Hits: 9.460 ]
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!
Avaliação de expressões matemáticas
Classe Java para a validação de CNPJ
Passkeys: A Evolução da Autenticação Digital
Instalação de distro Linux em computadores, netbooks, etc, em rede com o Clonezilla
Título: Descobrindo o IP externo da VPN no Linux
Armazenando a senha de sua carteira Bitcoin de forma segura no Linux
Enviar mensagem ao usuário trabalhando com as opções do php.ini
Instalação Microsoft Edge no Linux Mint 22
Como configurar posicionamento e movimento de janelas no Lubuntu (Openbox) com atalhos de teclado
Máquinas Virtuais com IP estático acessando Internet no Virtualbox
Tela GNU GRUP versão 2.12 ao reiniciar. Como posso resolver? (1)
Tela GNU GRUP versão 2.12 ao reiniciar. Como posso resolver? (1)