10
My application, when starting, does the first search in the database. How I use the Hibernate
, this first connection is a little more time consuming as it assembles the entire bank mapping. I’m thinking of adding a Splash Screen at the beginning, so that the user does not think that the application has locked or is not loading, but by the examples I saw, I must inform an amount of time for the Thread
carry. However, the charging time of the system varies according to the settings of the micro, if the system has already been opened on the machine or if it is still in memory.
My question is whether I can make Splash’s lifetime take the loading time of my system.
Below is an example of how I start my system and how I use 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);
}
}
Main 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")
........
I think you can take the automatic bar fill out of the thread, and at each load event, it puts a percentage on the bar.
– mutlei
Okay, there’s an example where I can base myself?
– DevAgil
Do a search on the methods
wait()
andnotify()
;– mutlei
You’re not using the right resources to work multiple threads in Swing. Read about using Swingworker
– brevleq