I have a JFrame, where a database connection is established immediately. This connection takes up to 2 seconds, meanwhile I want to show a message (or another JFrame). After the connection is established, the message should disappear.
I have a bad example, does anybody have a better idea?
public class Main extends JFrame {
View v = new View();
static JFrame loader = new JFrame();
static JLabel loading = new JLabel("Loading");
public Main() {
this.add(v);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setExtendedState(this.getExtendedState() | JFrame.MAXIMIZED_BOTH);
this.setBounds(100, 50, 800, 500);
loader.setBounds(500, 300, 100, 100);
loader.setVisible(true);
loader.add(loading);
}
public static void main(String[] args) {
Main m = new Main();
if (DB.INSTANCE.connect()) {
m.setVisible(true);
loader.setVisible(false);
} else {
loading.setText("DB ERROR");
}
}
}
If the task is to create a splash dialog (a frame shown during the application startup while some initialisation work is being done), here is a tutorial on how to do it with Swing’s SplashScreen: http://docs.oracle.com/javase/tutorial/uiswing/misc/splashscreen.html.