NetBeans 如何实现启动画面功能有效吗?

发布于 2024-10-17 06:00:38 字数 214 浏览 5 评论 0原文

NetBeans 新手,刚刚注意到在文件>>中项目属性>> “应用程序”对话框中有一个标记为“启动画面”的文本字段,允许您指定程序启动时要显示的图像的路径。

我想自定义启动屏幕的工作方式(添加进度条等),并且想从头开始编写代码,但不知道从哪里开始。基于 Java/Swing 的启动屏幕的最佳实践是什么?

感谢您的任何意见!

New to NetBeans and just noticed that in the File >> Project Properties >> Application dialog there is a text field labeled Splash Screen that allows you to specify a path to an image that you would like displayed when your program is launching.

I want to customize the way my splash screen works (adding a progress bar, etc.) and would like to code it from the ground up but don't know where to start. What are the best practices for Java/Swing-based splash screens?

Thanks for any and all input!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

痴梦一场 2024-10-24 06:00:38

项目属性->应用->启动画面允许您将图像添加到应用程序。此属性在 MANIFEST.MF 中设置一个名为 SplashScreen-Image: 的值,例如 SplashScreen-Image: META-INF/GlassFish316x159.jpg 此属性将自动使图像显示为闪屏。它在 NetBeans 内部不起作用,必须在 IDE 外部运行。

有一个教程启动屏幕初学者教程详细介绍了如何使用它。本教程是针对 NetBeans 6.8 完成的,但也适用于撰写本文时最新的 7.2.1。

The project properties -> Application -> Splash Screen allows you to add an image to an application. This property sets a value in the MANIFEST.MF called SplashScreen-Image: e.g. SplashScreen-Image: META-INF/GlassFish316x159.jpg This property will automatically cause the image to display as a splash screen. It does not work inside NetBeans, and must be run outside the IDE.

There is a tutorial Splash Screen Beginner Tutorial that details how to use it more detail. The tutorial was done for NetBeans 6.8, but will work on 7.2.1 which is the latest at the time of this post.

李白 2024-10-24 06:00:38

我不确定 NetBeans 是如何做到这一点的,但自版本 6 以来,JRE 支持启动屏幕。请参阅

I'm not sure how NetBeans does it, but Splash Screens are supported by the JRE since version 6. See http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/splashscreen/

沦落红尘 2024-10-24 06:00:38

启动屏幕只是 java.awt.Window 或未修饰的 javax.swing.JFrame 的实例。
要创建窗口,只需说new Window(null),然后设置大小和位置(使用takeit你可以计算屏幕中心的位置),然后说window.setVisible(true) >

由于这是您自己的窗口,您可以执行您想要的操作:设置布局、图像、向南添加进程栏等。

您还可以使用 JFrame:new JFrame().setUndecorated(true)`

Splash screen is just a instance of java.awt.Window or undecorated javax.swing.JFrame.
To create window just say new Window(null), then set size and position (using tookit you can calculate where the screen center is) and then say window.setVisible(true)

Due to this is your own window you can do what you want: set layout, image, add process bar to the SOUTH etc.

You can also use JFrame: new JFrame().setUndecorated(true)`

甲如呢乙后呢 2024-10-24 06:00:38

有几种方法可以做到这一点。

要制作一个简单的启动屏幕(图像),您可以在 java 应用程序的命令行中指定它。

这是一个简单的示例

java -splash:<file name> <class name>

但是,如果您想要进度条,你将不得不做一些更复杂的事情,并自己编写一些代码。这是通过以下方式完成的。

  1. 使用闪屏元素创建 JWindow(或 Window 或未修饰的 JFrame)组件
  2. 将其设置为可见
  3. 执行 Swing GUI 启动代码的其余部分
  4. 将 JFrame 设置为可见,然后立即将 JWindow 设置为可见(假)

这应该显示几乎立即启动,然后在应用程序完全加载后隐藏。

要查看一些启动屏幕代码,请查看此处。链接中的实现仅显示如何使用 -splash 命令实现您可以实现的目标,但它将为您提供一个良好的开始,还包括您请求的进度条。

There are a couple of ways to do this.

To do a simple splash screen (an image) you can specify this in the command line of you java application.

Here is a simple example

java -splash:<file name> <class name>

However, if you want a progress bar, you are going to have to do something a little more complicated, and write some code yourself. This is done in the following way.

  1. Create a JWindow (or Window or undecorated JFrame) component with your splash screen elements
  2. Set it to visible
  3. Do the rest of your Swing GUI startup code
  4. Set your JFrame to visible, then immediately follow with setting the JWindow to visible(false)

This should show the splash almost immediately, and then hide once the your application is fully loaded.

To see some splash screen code, take a look here. The implementation in the link only shows how to achieve what you can with the -splash command, but it will give you a good start to also include the progress bar that you requested.

蓝戈者 2024-10-24 06:00:38

我希望这对您有所帮助,这是一个如何使用虚拟进度栏为自己创建简单启动屏幕的小示例:

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

class SplashScreen extends JWindow
{

private static JProgressBar progressBar = new JProgressBar();
private static SplashScreen execute;
private static int count;   
private static Timer timer1;

public SplashScreen()
{                   
    Container container = getContentPane();
    container.setLayout(null);      

    JPanel panel = new JPanel();
    panel.setBorder(new javax.swing.border.EtchedBorder());
    panel.setBackground(new Color(255,255,255));
    panel.setBounds(10,10,348,150);
    panel.setLayout(null);
    container.add(panel);       

    JLabel label = new JLabel("Hello World!");
    label.setFont(new Font("Verdana",Font.BOLD,14));
    label.setBounds(85,25,280,30);
    panel.add(label);

    progressBar.setMaximum(50);
    progressBar.setBounds(55, 180, 250, 15);        
    container.add(progressBar);         
    loadProgressBar();                  
    setSize(370,215);
    setLocationRelativeTo(null);
    setVisible(true);
}
public void loadProgressBar()
{
    ActionListener al = new ActionListener()
    {
        public void actionPerformed(java.awt.event.ActionEvent evt)
        {
            count++;
            progressBar.setValue(count);
            if (count == 50){
                timer1.stop();
                execute.setVisible(false);

                            //load the rest of your application

            }               
        }};         
    timer1 = new Timer(50, al);
    timer1.start();
}

public static void main (String args[]){    
     execute = new SplashScreen();      
   }
}

干杯!

I hope this helps you, it is a small example of how to create yourself a simple splash screen using a dummy Progress Bar:

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

class SplashScreen extends JWindow
{

private static JProgressBar progressBar = new JProgressBar();
private static SplashScreen execute;
private static int count;   
private static Timer timer1;

public SplashScreen()
{                   
    Container container = getContentPane();
    container.setLayout(null);      

    JPanel panel = new JPanel();
    panel.setBorder(new javax.swing.border.EtchedBorder());
    panel.setBackground(new Color(255,255,255));
    panel.setBounds(10,10,348,150);
    panel.setLayout(null);
    container.add(panel);       

    JLabel label = new JLabel("Hello World!");
    label.setFont(new Font("Verdana",Font.BOLD,14));
    label.setBounds(85,25,280,30);
    panel.add(label);

    progressBar.setMaximum(50);
    progressBar.setBounds(55, 180, 250, 15);        
    container.add(progressBar);         
    loadProgressBar();                  
    setSize(370,215);
    setLocationRelativeTo(null);
    setVisible(true);
}
public void loadProgressBar()
{
    ActionListener al = new ActionListener()
    {
        public void actionPerformed(java.awt.event.ActionEvent evt)
        {
            count++;
            progressBar.setValue(count);
            if (count == 50){
                timer1.stop();
                execute.setVisible(false);

                            //load the rest of your application

            }               
        }};         
    timer1 = new Timer(50, al);
    timer1.start();
}

public static void main (String args[]){    
     execute = new SplashScreen();      
   }
}

Cheers!

江南月 2024-10-24 06:00:38

还可以考虑在 NetBeans 平台(基于 Swing 的 RCP)之上构建应用程序。众多好处之一:它配备了带有进度条的可定制启动屏幕。

进度条示例:
http://platform.netbeans.org/tutorials/nbm-paintapp.html#wrappingUp

将 Swing 应用程序移植到 NetBeans 平台:
http://platform.netbeans.org/tutorials/60/nbm-porting -basic.html

更多链接:

http://netbeans.org/features/platform/ index.html

http://netbeans.org/features/platform/all-文档.html

Also consider to build your application on top of the NetBeans Platform (a Swing-based RCP). One of the many benefits: it comes with a customizable splash screen with progress bar.

Sample progress bar:
http://platform.netbeans.org/tutorials/nbm-paintapp.html#wrappingUp

Port a Swing application to the NetBeans Platform:
http://platform.netbeans.org/tutorials/60/nbm-porting-basic.html

Further links:

http://netbeans.org/features/platform/index.html

http://netbeans.org/features/platform/all-docs.html

远昼 2024-10-24 06:00:38

如果您的应用程序是使用 NetBeans 平台构建的,则这里有一个有关启动屏幕自定义的教程:http://wiki.netbeans.org /Splash_Screen_Beginner_Tutorial

If your application is build using NetBeans Platform, then here's a tutorial about splash screen customisation: http://wiki.netbeans.org/Splash_Screen_Beginner_Tutorial

仅一夜美梦 2024-10-24 06:00:38

有一个相当于启动屏幕的 Javafx 示例。然而,这个启动屏幕基本上是一个 java swing 小程序,它从 javafx 调用并显示给用户,并使用进度条和加载内容的标题或多或少地模拟 eclipse 和 netbeans 启动屏幕。 这是链接。

您必须能够获取代码并分离出用 java swings 编写的启动屏幕代码并为自己使用。

这是一个自定义的 java swings 启动屏幕。因此为了使闪屏居中,它使用传统的

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension labelSize = l.getPreferredSize();
setLocation(screenSize.width / 2 - (labelSize.width / 2), 
                  screenSize.height / 2 - (labelSize.height / 2));

There is a sample Javafx equivalent of Splash screen. However this splash screen is basically a java swing applet that is called from javafx to be displayed to the user and simulates more or less eclipse and netbeans splash screen using progress bar and titles for the loaded contents. This is the link.

You must be able to get the code and separate out the splash screen code written in java swings and use it for yourself.

This is a custom java swings splash screen. and hence to center the splash screen it uses the traditional

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension labelSize = l.getPreferredSize();
setLocation(screenSize.width / 2 - (labelSize.width / 2), 
                  screenSize.height / 2 - (labelSize.height / 2));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文