-
Notifications
You must be signed in to change notification settings - Fork 1
/
SplashScreenFrame.java
218 lines (148 loc) · 6.3 KB
/
SplashScreenFrame.java
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package com;
//this is the code for the splash screen. This code is [art of the overal project iNBox(Intelligent Mail Box)...
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
public class SplashScreenFrame extends JFrame {
private static int splashWaitTime;
private static String splashScreenMessage;
private static LogInScreen logInscreen;
private static JPanel imagePanel;
private static JProgressBar progressBar;
private static ImageIcon splashImage;
private static ImageIcon splashImage2;
private static JLabel imgLabel;
public SplashScreenFrame() {
//CREATE FRAME WINDOW
super("iNBox");
setUndecorated(true);
setSize(500, 320);
setLocation(300, 150);
setVisible(true);
setLayout(null);
//ASSING WIDGET OBJECTS
splashImage = new ImageIcon(getClass().getResource("splash.png"));
splashImage2 = new ImageIcon(getClass().getResource("img_1.png"));
imagePanel = new JPanel();
imgLabel = new JLabel(splashImage);
progressBar = new JProgressBar(0, 100);
//SET WIDGET PROPERTIES
progressBar.setStringPainted(true);
progressBar.setString("Loading modules...");
progressBar.setForeground(Color.BLUE);
progressBar.setBackground(Color.gray);
imagePanel.setBackground(Color.blue);
progressBar.setBounds(0, 300, getContentPane().getSize().width, 20);
imgLabel.setBounds(0, 0, getContentPane().getSize().width, 319);
imagePanel.setBounds(0, 0, getContentPane().getSize().width, 319);
//ASSIN NEW logInScren class object this object is used for redisplaying the log in screen
logInscreen = new LogInScreen();
//ADD THE imageIcon to image panel
imagePanel.add(imgLabel);
//add components to the container (JFrame)
add(progressBar);
add(imagePanel);
try {
onRunBackgroundTask();
} catch (ClassNotFoundException e) {
}
}
//Application start up code
public void onRunBackgroundTask() throws ClassNotFoundException {
//create a seperate thread
Thread backgroundScanningThread = new Thread(
new Runnable() {
@Override
public void run() {
for (int taskLevel = 0; taskLevel <= 100; taskLevel++) {
simulateBackgroundTask(taskLevel, getSplashTime(taskLevel), getSplashScrenMessage(taskLevel));
}
}
}
);
backgroundScanningThread.start();
/**
* try { UIManager.setLookAndFeel(
*
* UIManager.getSystemLookAndFeelClassName() } catch
* (InstantiationException ex) {
* Logger.getLogger(SplashScreenFrame.class.getName()).log(Level.SEVERE,
* null, ex); } catch (IllegalAccessException ex) {
* Logger.getLogger(SplashScreenFrame.class.getName()).log(Level.SEVERE,
* null, ex); } catch (UnsupportedLookAndFeelException ex) {
* Logger.getLogger(SplashScreenFrame.class.getName()).log(Level.SEVERE,
* null, ex); }*
*/
//THIS METHOD SIMULATES THE BACKGROUND TASK ON THW SWING WORKER THREAD
}
//DETERMINE WAIT TIME FOR THE SPLASH
protected int getSplashTime(int levelOfTask) {
if (levelOfTask <= 45) {
progressBar.setBackground(Color.BLACK);
splashWaitTime = 100;
} else if (levelOfTask <= 50 && levelOfTask > 45) {
progressBar.setBackground(Color.GRAY);
splashWaitTime = 100;
} else if (levelOfTask <= 75 && levelOfTask > 50) {
splashWaitTime = 100;
} else if (levelOfTask <= 79 && levelOfTask > 75) {
splashWaitTime = 100;
} else if (levelOfTask <= 83 && levelOfTask > 79) {
splashWaitTime =1;
} else if (levelOfTask <= 85 && levelOfTask > 83) {
splashWaitTime = 1;
} else if (levelOfTask <= 100 && levelOfTask > 85) {
splashWaitTime = 1;
}
return splashWaitTime;
}
//DETERMINE MESSAGE TO BE DISPLAYED IN THE SPLASH
protected String getSplashScrenMessage(int levelOfTask) {
if (levelOfTask <= 30) {
splashScreenMessage = "Loading modules...";
} else if (levelOfTask <= 35 && levelOfTask > 30) {
splashScreenMessage = "Connecting to server...";
} else if (levelOfTask <= 45 && levelOfTask > 35) {
splashScreenMessage = "Obtaining app data...";
} else if (levelOfTask <= 75 && levelOfTask > 45) {
splashScreenMessage = "Creating workspace...";
} else if (levelOfTask <= 79 && levelOfTask > 75) {
splashScreenMessage = "creating workpace...";
} else if (levelOfTask <= 83 && levelOfTask > 79) {
splashScreenMessage = "Retrieving recent activities...";
} else if (levelOfTask <= 85 && levelOfTask > 83) {
splashScreenMessage = "Done modules";
} else if (levelOfTask <= 98 && levelOfTask > 85) {
splashScreenMessage = "Application start up completing... ";
}
else if (levelOfTask <= 100 && levelOfTask > 98) {
splashScreenMessage = "Application start up complete... ";
}
return splashScreenMessage;
}
protected void simulateBackgroundTask(int levelOfTask, int waitTimeInMillis, String taskDesctriptionToDisplay) {
progressBar.setString("" + taskDesctriptionToDisplay);
progressBar.setValue(levelOfTask);
try {
Thread.sleep(waitTimeInMillis);
} catch (InterruptedException e) {
}
if (levelOfTask == 100) {
setVisible(false);
logInscreen.setVisible(true);
}
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(
new Runnable() {
@Override
public void run() {
new SplashScreenFrame();
}
}
);
}
}