Graphics.drawString
似乎没有在SplashScreen
上绘制,其来源是带有透明元素的PNG。
享受我的Loader课程:
package view;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.SplashScreen;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class Loader {
public static void main(String[] args) {
final SplashScreen splash = SplashScreen.getSplashScreen();
final Graphics2D g;
// try {
// GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
// ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(System.getProperty("user.dir") + "\\data\\font\\PhantElemental.ttf")));
// } catch (IOException | FontFormatException e) {
// System.out.println("exception found");
// }
if(null != splash) {
g = splash.createGraphics();
renderSplashFrame(g, 0, splash);
splash.update();
displayUI(g, splash);
} else {
g = null;
}
}
private static void displayUI(final Graphics2D g, final SplashScreen splash) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException |
InstantiationException |
IllegalAccessException |
UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
for(int i = 0; i < 250; i++) {
renderSplashFrame(g, i, splash);
splash.update();
try {
Thread.sleep(10);
} catch(InterruptedException e) {
System.out.println("Thread sleep exception, on outer splashscreen timer!");
}
if(i == 249) {
splash.close();
}
}
}
});
}
private static void renderSplashFrame(Graphics2D g, int frame, SplashScreen splash) {
final String[] comps = {
"Initialising",
"Preparing logic",
"Preparing UI",
"Finalising"};
g.setComposite(AlphaComposite.Clear);
g.fillRect(30, 150, 160, 50);
g.setPaintMode();
g.setColor(Color.RED);
g.setFont(new Font("Sans", Font.PLAIN, 30));
g.drawString(comps[(frame / 63) % 4] + " . . ", 40, 160);
}
public class UnsupportedClassException extends Exception {
private static final long serialVersionUID = 1L;
public UnsupportedClassException() {
super();
}
}
}
您可能需要使用文本的目标位置(和清除矩形)。显然,因为它使用了闪屏,你需要打包和运行,除非有一些神奇的方式来预测这个我不知道的日食!
这种方法在历史上对我来说是非透明的SplashScreen
来源。