Repository navigation
Expand file tree
/
Copy pathSplash.java
More file actions
83 lines (70 loc) · 2.54 KB
/
Copy pathSplash.java
File metadata and controls
83 lines (70 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package Hotel.Management.System;
import javax.swing.*;
import java.awt.*;
public class Splash extends JFrame {
private float alpha = 0f; // transparency for fade-in
private JLabel titleLabel;
private JLabel loadingLabel;
Splash() {
// Load background PNG
ImageIcon originalIcon = new ImageIcon(ClassLoader.getSystemResource("icon/Splash.png"));
Image image = originalIcon.getImage().getScaledInstance(875, 700, Image.SCALE_SMOOTH);
ImageIcon scaledIcon = new ImageIcon(image);
JLabel bgLabel = new JLabel(scaledIcon);
bgLabel.setBounds(0, 0, 858, 680);
// Project Title
titleLabel = new JLabel(" Hotel CHIKALAX ", SwingConstants.CENTER);
titleLabel.setFont(new Font("Serif", Font.BOLD, 28));
titleLabel.setForeground(new Color(255, 215, 0, 0)); // start invisible
titleLabel.setBounds(0, 20, 858, 40);
// Loading animation text
loadingLabel = new JLabel("Loading", SwingConstants.CENTER);
loadingLabel.setFont(new Font("SansSerif", Font.BOLD, 20));
loadingLabel.setForeground(Color.WHITE);
loadingLabel.setBounds(0, 600, 858, 30);
// Add components
setLayout(null);
add(titleLabel);
add(loadingLabel);
add(bgLabel);
setLocation(300, 80);
setSize(858, 680);
setVisible(true);
// Start animations
startFadeIn();
startLoadingText();
try {
Thread.sleep(6000); // Show splash for 6 sec
new Login(); // go to login screen
setVisible(false);
} catch (Exception e) {
e.printStackTrace();
}
}
private void startFadeIn() {
Timer timer = new Timer(50, e -> {
alpha += 0.05f;
if (alpha > 1f) {
alpha = 1f;
((Timer) e.getSource()).stop();
}
// Apply fade effect to title
titleLabel.setForeground(new Color(255, 215, 0, (int) (alpha * 255)));
});
timer.start();
}
private void startLoadingText() {
Timer timer = new Timer(500, e -> {
String text = loadingLabel.getText();
if (text.equals("Loading...")) {
loadingLabel.setText("Loading");
} else {
loadingLabel.setText(text + ".");
}
});
timer.start();
}
public static void main(String[] args) {
new Splash();
}
}