Splash Screen!!!
Publicado por Rogério M. de Queiroz 02/03/2007
[ Hits: 9.492 ]
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!
Planilha de cálculo para multa judicial
Crivo de Eratóstenes Simples em Java
Pesquisa Binaria em um vetor ordenado
Criar entrada (menuentry) ISO no Grub
Como gerar qualquer emoji ou símbolo unicode a partir do seu teclado
Instalar o VIM 9.1 no Debian 12
Como saber o range de um IP público?
Muitas dificuldades ao instalar distro Linux em Notebook Sony Vaio PCG-6131L (VPCEA24FM)
Slackpkg+ (Slackpkg Plus) está de volta!
Como dividir duas janelas igualmente e lado-a-lado na sua tela
Ocomon 6.0.1 - Problemas ao editar configurações estendidas (7)
instalar o Linux em computadores Acer novos (7)
Será possível instalar Linux Mint LMDE em Sony Vaio? (19)
O livro "Linux - Guia do Administrador do Sistema (Rubem E. Ferre... (1)