我想为我的Java应用程序创建启动画面。我设法使用NetBeans默认工具来完成此操作,该工具允许我放置一些图像。但是,我希望有一些“活动”,例如显示应用程序加载状态的进度条,一些动态文本等。我的Java应用程序的动态启动画面
我该怎么做?我需要知道什么才能开始做这样的事情?
我想为我的Java应用程序创建启动画面。我设法使用NetBeans默认工具来完成此操作,该工具允许我放置一些图像。但是,我希望有一些“活动”,例如显示应用程序加载状态的进度条,一些动态文本等。我的Java应用程序的动态启动画面
我该怎么做?我需要知道什么才能开始做这样的事情?
关键是要建立一个飞溅然后使用swing调用屏幕,然后使用Java反射方法调用该方法,该方法位于另一个.java文件中,该方法会阻止该应用程序。加载完成后,处理你的启动画面。
检查代码后,您将了解它是如何工作的,现在按自己的方式进行自定义。
下面是一些代码:
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JDialog;
/**
*
* @author martijn
*/
public class Splash {
public static void splash() {
try {
final BufferedImage img = ImageIO.read(Splash.class.getResourceAsStream("/path/to/your/splash/image/splash.png"));
JDialog dialog = new JDialog() {
@Override
public void paint(Graphics g) {
g.drawImage(img, 0, 0, null);
}
};
// use the same size as your image
dialog.setPreferredSize(new Dimension(450, 300));
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
dialog.setUndecorated(true);
dialog.pack();
dialog.setLocationRelativeTo(null);
dialog.setVisible(true);
dialog.repaint();
try {
// Now, we are going to init the look and feel:
Class uim = Class.forName("javax.swing.UIManager");
uim.getDeclaredMethod("setLookAndFeel", String.class).invoke(null, (String) uim.getDeclaredMethod("getSystemLookAndFeelClassName").invoke(null));
// And now, we are going to invoke our loader method:
Class clazz = Class.forName("yourpackage.YourClass");
dialog.dispose();
// suppose your method is called init and is static
clazz.getDeclaredMethod("init").invoke(null);
} catch (Exception ex) {
ex.printStackTrace();
}
dialog.dispose();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
这里是Java教程,引导你准确地完成你想要做的事情。你可以在命令行上设置的图像,使其立即显示,那么你可以操纵它一旦JVM初始化添加文本,进度条等
http://download.oracle.com/javase/tutorial/uiswing/misc/splashscreen.html