以编程方式显示SplashScreen

evo*_*pid 8 java splash-screen

我目前正在研究Java应用程序,它是我的第一个Java应用程序.所以我创建了一个文件Splash.png并将其放入resources应用程序的源文件夹中.

我已经设法在启动时使用JVM参数显示Splash图像-splash:resources/Splash.png,但我的问题是;

如何再次显示此启动画面,但是以编程方式?

我需要About菜单项的这个功能.

evo*_*pid 2

感谢您的大力帮助。我认为实际上没有任何函数可以做到这一点,所以我只是编写了一个 JFrame,我可以在启动时显示它而不是启动屏幕。对于有人可能也需要代码的情况,我只是将其发布在这里:

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class AboutWindow extends JFrame implements MouseListener {

    public AboutWindow() {
        // show splash screen image
        ImageIcon icon = new ImageIcon("resources/Splash.png");
        JLabel label = new JLabel(icon);
        getContentPane().add(label, BorderLayout.CENTER);

        // setup window correct
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setResizable(false);
        setUndecorated(true);

        pack();

        // place it at the right position
        Dimension windowDimension = Toolkit.getDefaultToolkit().getScreenSize();

        int x = (windowDimension.width-getWidth())/2;
        int y = (windowDimension.height-getHeight())/3;

        setLocation(x, y);

        // add the mouse listener
        addMouseListener(this);
    }

    @Override
    public void mouseClicked(MouseEvent me) {
        dispose();
    }

    @Override
    public void mousePressed(MouseEvent me) {
        // do nothing
    }

    @Override
    public void mouseReleased(MouseEvent me) {
        // do nothing
    }

    @Override
    public void mouseEntered(MouseEvent me) {
        // do nothing
    }

    @Override
    public void mouseExited(MouseEvent me) {
        // do nothing
    }
}
Run Code Online (Sandbox Code Playgroud)