Criando Tela de Apresentação em Java
Fala galera! Depois de um tempo fora (cerca de 1 mês), por ócios do ofício, volto com um post bem legal de uma necessidade que tive em um projeto que estou atuando. Um dos módulos do projeto era desktop, e com isso, percebi que a tela de apresentação estava muito sem graça.
Vendo isto, recordei de alguns sistemas e até mesmo jogos que, sempre antes da tela principal, aparecem algumas janelas com logo da empresa, ano de desenvolvimento etc. Então pensei "vou desenvolver isso". Então o fiz e hoje mostro para vocês como criar as suas telas de apresentação.
import java.awt.*;
import javax.swing.*;
public class SplashScreen extends JWindow {
private int duration;
public SplashScreen(int d) {
duration = d; }
// Este é um método simples para mostrar uma tela de apresentção
import javax.swing.*;
public class SplashScreen extends JWindow {
private int duration;
public SplashScreen(int d) {
duration = d; }
// Este é um método simples para mostrar uma tela de apresentção
// no centro da tela durante a quantidade de tempo passada no construtor
public void showSplash() {
JPanel content = (JPanel)getContentPane();
content.setBackground(Color.white);
// Configura a posição e o tamanho da janela
JPanel content = (JPanel)getContentPane();
content.setBackground(Color.white);
// Configura a posição e o tamanho da janela
int width = 450;
int height =115;
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
int x = (screen.width-width)/2;
int y = (screen.height-height)/2;
setBounds(x,y,width,height);
// Constrói o splash screen
JLabel label = new JLabel(new ImageIcon("devmedia.gif"));
JLabel copyrt = new JLabel
("Copyright 2006, DevMedia", JLabel.CENTER);
copyrt.setFont(new Font("Sans-Serif", Font.BOLD, 12));
content.add(label, BorderLayout.CENTER);
content.add(copyrt, BorderLayout.SOUTH);
Color oraRed = new Color(156, 20, 20, 255);
content.setBorder(BorderFactory.createLineBorder(oraRed, 10));
// Torna visível
setVisible(true);
// Espera ate que os recursos estejam carregados
try { Thread.sleep(duration); } catch (Exception e) {}
setVisible(false);
}
public void showSplashAndExit() {
showSplash();
System.exit(0);
}
public static void main(String[] args) {
// Mostra uma imagem com o título da aplicação
SplashScreen splash = new SplashScreen(10000);
splash.showSplashAndExit();
}
}
Com as devidas adaptações para meu projeto, o código ficou assim:
public class SplashScreen extends JWindow implements Runnable {
private int duration;
boolean vai;
public static String servidor;
public SplashScreen(int d) {
duration = d;
}
@Override
public void run() {
vai = true;
while (vai) {
JPanel content = (JPanel) getContentPane();
content.setBackground(Color.white);
// Configura a posição e o tamanho da janela
int width = 450;
int height = 400;
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
int x = (screen.width - width) / 2;
int y = (screen.height - height) / 2;
setBounds(x, y, width, height);
// Constrói o splash screen
JLabel label = new JLabel(new javax.swing.ImageIcon(getClass().getResource("/br/com/sispav/imagens/logoSplash.png")));
JLabel copyrt = new JLabel("Copyright 2013, Infomobile/Execute/Elite Segurança.\nTodos os direitos resevados.", JLabel.CENTER);copyrt.setFont(new Font("Sans-Serif", Font.BOLD, 10));
content.add(label, BorderLayout.CENTER);
content.add(copyrt, BorderLayout.SOUTH);
Color oraRed = new Color(121, 158, 191);
content.setBorder(BorderFactory.createLineBorder(oraRed, 10));
// Torna visível
setVisible(true);
// Espera ate que os recursos estejam carregados
try {
Thread.sleep(duration);
} catch (Exception e) {
}
inicia();
setVisible(false);
vai = false;
}
}
public static void main(String[] args) {
// Mostra uma imagem com o título da aplicação
SplashScreen splash = new SplashScreen(10000);
splash.run();
}
Espero que tenham gostado! Abraços!
Analista Especialista Em Desenvolvimento de Sistemas UFPA/FACI
3 Publicações Nacionais e 1 Internacional.
Coordenador do Grupo de Pesquisa e Desenvolvimento de Softwares Faculdade Ideal
Moderador do BelJug.
Email: brunor.santos@yahooo.com.br
Criador do Blog JaTAvaNaMente: http://javanamente.blogspot.
Comentários
Postar um comentário