Repository navigation
Expand file tree
/
Copy pathLoadingScreenDemo.java
More file actions
66 lines (58 loc) · 1.63 KB
/
Copy pathLoadingScreenDemo.java
File metadata and controls
66 lines (58 loc) · 1.63 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
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JWindow;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class LoadingScreenDemo extends JWindow {
private static final long serialVersionUID = 1L;
JPanel panel = new JPanel();
JProgressBar progressBar = new JProgressBar();
public LoadingScreenDemo() {
panel.setBackground(Color.YELLOW);
panel.setLayout(new BorderLayout());
panel.add(progressBar, BorderLayout.SOUTH);
panel.setFocusable(true);
progressBar.setStringPainted(true);
add(panel);
Timer timer = new Timer(100, new ActionListener() {
int i = 0;
public void actionPerformed(ActionEvent evt) {
progressBar.setValue(i);
i++;
panel.repaint();
if (i == 100) {
((Timer) evt.getSource()).stop();
dispose();
}
}
});
timer.start();
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
LoadingScreenDemo w = new LoadingScreenDemo();
w.setSize(640, 480);
w.setLocationRelativeTo(null);
w.setVisible(true);
}
});
}
}