Java 以编程方式显示屏幕
我目前正在开发一个Java应用程序,这是我的第一个Java应用程序。因此,我创建了一个文件Java 以编程方式显示屏幕,java,splash-screen,Java,Splash Screen,我目前正在开发一个Java应用程序,这是我的第一个Java应用程序。因此,我创建了一个文件Splash.png,并将其放入应用程序的源文件夹resources 我已经用JVM参数-Splash:resources/Splash.png在启动时显示了Splash图像,但我的问题是 如何以编程方式再次显示此初始屏幕? 我需要将此功能用于关于菜单项。使用java.awt.SplashScreen类 顺便说一句,我不知道JVM有这个很酷的选项“-splash”。所以,谢谢你的信息 是以编程方式使用闪屏的
Splash.png
,并将其放入应用程序的源文件夹resources
我已经用JVM参数-Splash:resources/Splash.png
在启动时显示了Splash图像,但我的问题是
如何以编程方式再次显示此初始屏幕?
我需要将此功能用于
关于菜单项。使用java.awt.SplashScreen
类
顺便说一句,我不知道JVM有这个很酷的选项“-splash”。所以,谢谢你的信息 是以编程方式使用闪屏的一个突出例子
这里还描述了-splash
如何以编程方式再次显示此初始屏幕
功能使用的基于AWT的API提供了在这方面可能很方便的方法。在屏幕上显示任何GUI元素之前,需要在main()
的早期获取SplashScreen
实例
当需要显示图像时,有许多可能性最适合不同的任务和使用图像的方式。显示它的最简单方法之一是:
JLabel splashLabel = new JLabel(new ImageIcon(splashURL));
在mKorbel提到的对话框或窗口中弹出,以在屏幕上显示。通常,对于“类似飞溅”的图像,我们希望使用纯AWT,但这种情况有所不同,因为GUI已经在屏幕上,所以Swing可能已经加载并准备就绪。感谢您的大力帮助。
我认为实际上没有任何函数可以做到这一点,所以我只编写了一个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
}
}
在启动屏幕出现之前,可能有JWindow或JDialog(未装饰)添加setType(Type.UTILITY)会很好:)setLocationRelativeTo(null)是将其放置在正确位置的快捷方式可能链接已更改,但到目前为止,本文实际上没有解释如何以编程方式显示启动屏幕,只能通过-splash
参数或使用清单。