Pages

Java Splash/Loading Screen

SplashScreen splash = new SplashScreen(2000);

splash.showSplashAndExit();

-----------------------------------------------------------

public class SplashScreen extends JWindow {


    private int duration;


    public SplashScreen(int d) {

        duration = d;

    }


    public void showSplash() throws Exception {


        JPanel content = (JPanel) getContentPane();

        content.setBackground(Color.white);


        int width = 820;

        int height = 462;

        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

        int x = (screen.width - width) / 2;

        int y = (screen.height - height) / 2;

        setBounds(x, y, width, height);


        JLabel label = new JLabel();

        label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/verbita_logo.png")));

        JLabel copyrt = new JLabel("", JLabel.CENTER);

        copyrt.setFont(new Font("Sans-Serif", Font.BOLD, 12));

        content.add(label, BorderLayout.CENTER);

        content.add(copyrt, BorderLayout.SOUTH);

        //Color oraRed = new Color(156, 20, 20,  255);

        //content.setBorder(BorderFactory.createLineBorder(oraRed, 10));

        setVisible(true);

        try {

            Thread.sleep(duration);

        } catch (Exception e) {

            e.printStackTrace();

            JOptionPane.showMessageDialog(content, e.getMessage(),"Alert!",JOptionPane.ERROR_MESSAGE);

        }


        setVisible(false);


    }


    public void showSplashAndExit() throws Exception {

        showSplash();

    }

No comments:

Post a Comment