Cấu hình tải lớp chính của tôi từ một tệp sau đó hiển thị khung. Tôi muốn tạo một màn hình giật gân với thanh tiến trình như Eclipse để tiến trình sẽ tăng lên trong khi tệp đang được tải và giật gân biến mất sau khi tệp được tải. Sau đó khung chính của tôi được tải.Tạo màn hình giật gân với thanh tiến trình như Eclipse
đang MainClass:
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
"classpath:/META-INF/spring/applicationContext.xml");
// splash with progress load till this file is loaded
UserDao userDao = context.getBean(UserDao.class);
isRegistered = userDao.isRegistered();
System.out.println("registered: " + isRegistered);
if (isRegistered) {
// progress finish and hide splash
log.debug("user is registered"); // show frame1
} else {
// progress finish and hide splash
log.debug("user is not registered"); // show frame2
}
}
Tôi không có nhiều kinh nghiệm với Swing, vì vậy xin vui lòng tư vấn làm thế nào để thực hiện điều đó.
UPDATE: tôi đã tìm thấy ví dụ sau, nhưng nó có chút vấn đề:
khi truy cập được không vượt quá số nó nên dừng lại ở (300) nó giữ đếm mãi mãi mà không dừng lại bộ hẹn giờ và ẩn màn hình giật gân.
tôi muốn ràng buộc bộ đếm để tải tệp, vì vậy trong khi tệp được tải tiến trình được tải cho đến khi tệp được tải thì tiến trình hoàn thành và màn hình splash biến mất.
@SuppressWarnings("serial") @Component public class SplashScreen extends JWindow { static boolean isRegistered; static Log log = LogFactory.getLog(SplashScreen.class); private static JProgressBar progressBar = new JProgressBar(); private static SplashScreen execute; private static int count; private static Timer timer1; public SplashScreen() { Container container = getContentPane(); container.setLayout(null); JPanel panel = new JPanel(); panel.setBorder(new javax.swing.border.EtchedBorder()); panel.setBackground(new Color(255, 255, 255)); panel.setBounds(10, 10, 348, 150); panel.setLayout(null); container.add(panel); JLabel label = new JLabel("Hello World!"); label.setFont(new Font("Verdana", Font.BOLD, 14)); label.setBounds(85, 25, 280, 30); panel.add(label); progressBar.setMaximum(50); progressBar.setBounds(55, 180, 250, 15); container.add(progressBar); loadProgressBar(); setSize(370, 215); setLocationRelativeTo(null); setVisible(true); } public void loadProgressBar() { ActionListener al = new ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { count++; progressBar.setValue(count); if (count == 300) { timer1.stop(); execute.setVisible(false); return; } } }; timer1 = new Timer(50, al); timer1.start(); } public static void main(String[] args) { execute = new SplashScreen(); ApplicationContext context = new ClassPathXmlApplicationContext( "classpath:/META-INF/spring/applicationContext.xml"); UserDao userDao = context.getBean(UserDao.class); isRegistered = userDao.isRegistered(); if (isRegistered) { // show frame 1 } else { // show frame 2 } } }
Bạn đã xem [câu hỏi này] (http://stackoverflow.com/questions/2089359/java-6-splash-screen?rq=1)? Nó có một số liên kết tốt. –