My application, when starting, does the first search in the database. Since I use Hibernate
, this first connection is a bit more time consuming because it assembles all the database mapping. I'm thinking of adding a Splash Screen at the beginning, so the user does not think that the application has crashed or is not loading, but from the examples I've seen, I have to give an amount of time to Thread
load. However, the system load time varies depending on the microcontroller settings, whether the system has already been opened in the machine or is still in memory.
My question is whether I can make Splash's lifespan take a long time to load my system.
Below is an example of how I start my system and how it generates my Splash.
Splash.java
....
/**
*
* @author desenvolvimento
*/
public class Splash extends JWindow {
AbsoluteLayout absoluto;
AbsoluteConstraints absimagem, absbarra;
ImageIcon image;
JLabel jLabel;
JProgressBar barra;
public Splash() {
absoluto = new AbsoluteLayout();
absimagem = new AbsoluteConstraints(0, 0);
absbarra = new AbsoluteConstraints(0, 284);
jLabel = new JLabel();
image = new ImageIcon(this.getClass().getResource("/imagem/Logo.png"));
jLabel.setIcon(image);
barra = new JProgressBar();
barra.setPreferredSize(new Dimension(285, 10));
this.getContentPane().setLayout(absoluto);
this.getContentPane().add(jLabel, absimagem);
this.getContentPane().add(barra, absbarra);
this.getContentPane().setBackground(Color.white);
new Thread() {
public void run() {
int i = 0;
while (i < 101) {
barra.setValue(i);
i++;
try {
sleep(150);
} catch (InterruptedException ex) {
Logger.getLogger(Splash.class.getName()).log(Level.SEVERE, null, ex);
}
}
TelaLogin x = new TelaLogin();
x.setVisible(true);
}
}.start();
this.pack();
this.setVisible(true);
this.setLocationRelativeTo(null);
}
}
Principal.java
public class Agil {
public static void main(String[] args) {
TelaLogin telaLogin = new TelaLogin();
telaLogin.validate();
telaLogin.pack();
telaLogin.setVisible(false);
}
}
TelaLogin.java
public class TelaLogin extends javax.swing.JFrame {
/**
* Creates new form TelaLogin
*/
public TelaLogin() {
initComponents();
new Splash();
EmitenteDAO emitentedao = new EmitenteDAO();
String nomeFantasia = emitentedao.getEmitente();
LbEmpresaLogin.setText(nomeFantasia);
LeituraXmlConfig config = new LeituraXmlConfig();
if (config.getValidaConfig().equals("0")) {
//Inicia configuração
} else if (config.getValidaConfig().equals("1")) {
}
URL url = this.getClass().getResource("imagem/icon_32.png");
Image iconeTitulo = Toolkit.getDefaultToolkit().getImage(url);
this.setIconImage(iconeTitulo);
TxUsuarioLogin.setDocument(new EntradaUpperCase());
}
Session session = Session.getSession();
@SuppressWarnings("unchecked")
........