Splashscreen.getSplashScreen();的Java 9 Splashscreen问题

时间:2019-06-11 10:42:42

标签: java splash-screen

我的Java启动画面无法正常工作!我正在使用Eclipse和Java9。在引用https://docs.oracle.com/javase/tutorial/uiswing/misc/splashscreen.html时,我尝试使用方法SplashScreen.getScreenSplash();。但这是行不通的。而是错误消息指出此方法不存在。 这是我的代码:

import java.awt.*;
import javax.swing.*;

public class SplashScreen extends JFrame {
    private SplashScreen sp;
    private JLabel label;

    public SplashScreen() {
        super("SplashScreen");
        setSize(300, 200);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setLayout(new BorderLayout());
        label = new JLabel("Welcome");
        label.setFont(new Font("Arial", Font.BOLD, 20));
        add(label, BorderLayout.CENTER);
        sp = SplashScreen.getScreenSplash();

        if(sp != null) {
            Graphics2D g = sp.createGraphics();
            g.setComposite(AlphaComposite.Clear);
            g.setPaintMode();
            //printing the progress bar
            try {
                for(int i = 0; i <= 100; i++) {
                g.setColor(Color.BLACK);
                g.fillRect(100, 200, 200, 20);
                g.setColor(Color.GREEN);
                g.fillRect(100, 200, 2*i, 20);
                sp.update(g);
                Thread.sleep(100);
                }
                catch (Exception e) {
                    System.out.println(e.getMessage());
                }
            }
        }
        setVisible(true);


    }

}    

有人知道发生了什么变化吗? 谢谢!

1 个答案:

答案 0 :(得分:0)

 SplashScreen.getScreenSplash() !=  SplashScreen.getSplashScreen();

您把单词混在一起了。