-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSplashScreen.java
More file actions
125 lines (105 loc) · 3.88 KB
/
Copy pathSplashScreen.java
File metadata and controls
125 lines (105 loc) · 3.88 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package quest;
import javax.swing.JProgressBar;
class BaseJPanel extends javax.swing.JPanel {
private String imagePath;
public BaseJPanel(String imagePath) {
initComponents();
this.imagePath = imagePath;
}
@Override
public void paintComponent(java.awt.Graphics g) {
if(imagePath == null){
super.paintComponent(g);
return;
}
java.awt.Image img = new javax.swing.ImageIcon(imagePath).getImage();
g.drawImage(img, 0, 0, null);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
setLayout(null);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}
public class SplashScreen extends javax.swing.JFrame {
/**
* Generated serialVersionUID
*/
private static final long serialVersionUID = -4936210912624268230L;
//private static final Logger log = LogManager.getLogger(SplashFrame.class);
private static final int JPROGRESS_MAX = 1;
private BaseJPanel splash;
private JProgressBar jpbar;
public SplashScreen()
{
initComponents();
//log.info("Initializing Splash Screen");
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
this.setSize(800, 510);
splash = new BaseJPanel("images/splash.jpg");
jpbar = new JProgressBar(0, JPROGRESS_MAX);
jpbar.setBorderPainted(false);
jpbar.setMaximum(JPROGRESS_MAX);
this.add(splash, 0);
splash.setBounds(0, 0, 800, 500);
this.add(jpbar, 1);
jpbar.setBounds(0, 500, 800, 10);
splash.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
if (jpbar.getValue() >= JPROGRESS_MAX) {
showMainScreen();
}
}
});
new JPBarAnimationThread(1, jpbar).start();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(255, 255, 204));
setBounds(new java.awt.Rectangle(260, 200, 200, 375));
setFocusTraversalPolicyProvider(true);
setForeground(new java.awt.Color(204, 255, 204));
setName("Dataless Frame"); // NOI18N
setUndecorated(true);
setResizable(false);
getContentPane().setLayout(null);
setSize(new java.awt.Dimension(800, 500));
setLocationRelativeTo(null);
}
final void showMainScreen() {
MainFrame obj = new MainFrame();
obj.mainFrame();
this.dispose();
}
private class JPBarAnimationThread extends Thread {
private int step;
private JProgressBar bar;
public JPBarAnimationThread(int step, JProgressBar bar) {
this.step = step;
this.bar = bar;
}
@Override
public void run() {
super.run(); //To change body of generated methods, choose Tools | Templates.
while (bar.getValue() < bar.getMaximum()) {
try {
Thread.sleep(500);
bar.setValue(bar.getValue() + step);
} catch (Exception e) {
System.out.println("Error occured in progress bar.");
}
}
showMainScreen();
}
}
}