-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameSplashScreen.java
More file actions
104 lines (89 loc) · 2.45 KB
/
GameSplashScreen.java
File metadata and controls
104 lines (89 loc) · 2.45 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package GUI;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.JWindow;
import javax.swing.SwingConstants;
import javax.swing.Timer;
public class GameSplashScreen extends JWindow {
int currentProgress = 1;
int colorCode = 1;
JLabel lblGame = new JLabel("GAME-2016");
boolean isVisible = false;
Timer timer;
JProgressBar progressBar = new JProgressBar();
private Icon icon = new ImageIcon(GameSplashScreen.class.getResource("giphy.gif"));
public static void main(String[] args) {
GameSplashScreen frame = new GameSplashScreen();
frame.setVisible(true);
}
/**
* Create the frame.
*/
public GameSplashScreen() {
getContentPane().setBackground(Color.CYAN);
// setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 658, 549);
getContentPane().setLayout(null);
JLabel lblNewLabel = new JLabel("");
lblNewLabel.setIcon(icon);
lblNewLabel.setBounds(31, 32, 601, 311);
getContentPane().add(lblNewLabel);
progressBar.setForeground(Color.MAGENTA);
progressBar.setStringPainted(true);
progressBar.setBounds(21, 433, 580, 50);
getContentPane().add(progressBar);
lblGame.setHorizontalAlignment(SwingConstants.CENTER);
lblGame.setFont(new Font("Tahoma", Font.BOLD, 18));
lblGame.setBounds(170, 354, 254, 68);
getContentPane().add(lblGame);
doProgress();
}
private void doProgress() {
timer = new Timer(50, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
lblGame.setVisible(isVisible);
isVisible = !isVisible;
if (isVisible) {
switch (colorCode) {
case 1:
lblGame.setForeground(Color.RED);
break;
case 2:
lblGame.setForeground(Color.GREEN);
break;
case 3:
lblGame.setForeground(Color.BLUE);
break;
case 4:
lblGame.setForeground(Color.MAGENTA);
break;
}
if (colorCode < 5) {
colorCode++;
} else {
colorCode = 1;
}
}
if (currentProgress < 100) {
progressBar.setValue(currentProgress);
currentProgress++;
} else {
timer.stop();
MainScreen mainScreen = new MainScreen();
mainScreen.setVisible(true);
GameSplashScreen.this.setVisible(false);
GameSplashScreen.this.dispose();
}
}
});
timer.start();
}
}