Linux - Java 应用程序的启动屏幕

发布于 2024-10-12 14:15:17 字数 399 浏览 6 评论 0原文

在 Windows 上,我使用 Exe4J 来启动我的 Java 应用程序。这具有以下优点:

  • 在 Java 启动之前显示的启动屏幕
  • 可以在启动期间更新启动屏幕上的标签,直到应用程序完全加载(“初始化通量补偿器”、“重新排序高半字节”等)

现在我想要在 Linux 上实现这一点。我使用 Shell 脚本启动我的应用程序,但希望有一种简单的方法来显示某种带有标签的启动 GUI,我可以在启动期间从我的 shell 脚本进行更新。

有没有一种简单的方法可以从 shell 脚本启动最小的 GUI,并从 shell 脚本更新其中的标签,而无需为 Linux(甚至可能是 Mac OS X)编译单独的可执行文件?

PS:我不想在启动屏幕中使用 Java 构建,因为标签必须动态更新。

On Windows I use Exe4J to start my Java Application. This has the following advantages:

  • Splashscreen which shows before Java starts
  • Possibility to update a Label on the splash screen during the startup, until the application is folly loaded ("Initializing Flux compensator","Reordering high nibbles", etc.)

Now I want to implement this on Linux. I start my App with a Shell script, but would love an easy way to show some kind of splash GUI with a label on it, which I can update from my shell script during startup.

Is there an easy way to fire up a minimal GUI from a shell script, and to update the label in it from the shell script, without having to compile a separate executable for it for linux (and maybe even Mac OS X)?

PS: I don't want to use the Java build in splash screen because of the Label which has to be updated dynamically.

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

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

发布评论

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

评论(3

扬花落满肩 2024-10-19 14:15:17

屏幕启动的标准 Java 1.6+ 解决方案支持在启动上自定义绘图 Screensplash教程

这是一个启动控制器的示例,它有一个主要方法——使用启动参数运行它以查看结果。

package somepackage;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.SplashScreen;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Rectangle2D;

public class SplashController implements ActionListener {
    private static final int X = 20, W = 300;
    private static final int TEXT_H = 10, BAR_H = 10;

    private int textY, barY;
    private int barPos = 0;

    private final SplashScreen splash;
    private Graphics2D graph;

    public SplashController(final int msgXOffset, final int msgYOffset) {
    splash = SplashScreen.getSplashScreen();
    if (splash == null) {
         System.out.println("Error: no splash image specified on the command line");
         return;
    }

   // compute base positions for text and progress bar
   final Dimension splashSize = splash.getSize();
   textY = splashSize.height - msgYOffset;
   barY = splashSize.height - msgYOffset;

   graph = splash.createGraphics();
   //timer.start();
}

public SplashController() {
    this(30, 30);
}

@Override
public void actionPerformed(final ActionEvent e) {
    drawSplashProgress(msg);
}

public void closeSplash() {
    if (splash != null) {
        splash.close();
    }
}

private String msg;

public void drawSplashProgress(final String msg) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            SplashController.this.msg = msg;
            graph.setRenderingHint(RenderingHints.KEY_INTERPOLATION,                              RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            graph.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            graph.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            graph.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

            // clear what we don't need from previous state
            graph.setComposite(AlphaComposite.Clear);

            final FontMetrics fm = graph.getFontMetrics();
            final Rectangle2D textsize = fm.getStringBounds(msg, graph);

            graph.fillRect(X, textY - 1, W, (int) textsize.getHeight() + 5);
            if (barPos == 0) {
                graph.fillRect(X - 3, barY, W + 10, BAR_H);
            }

            // draw new state
            graph.setPaintMode();

            // draw message
            graph.setColor(Color.BLACK);
            graph.drawString(msg, X, textY + TEXT_H);
            try {
                splash.update();
            } catch (final IllegalStateException e) {
               // can be ignored
            }
        }
     });
}

public static void main(final String args[]) throws Exception {
    final SplashController test = new SplashController();
    for (int i = 0; i < 50; i++) {
       test.drawSplashProgress("Progress step number " + i);
       Thread.sleep(250);
    }
    test.closeSplash();
}  
}

The standard Java 1.6+ solution for screen splash does support custom drawing on the splash Screensplash Tutorial.

Here is an example for a splash controller, which has a main method -- run it with a splash parameter to see the result.

package somepackage;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.SplashScreen;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Rectangle2D;

public class SplashController implements ActionListener {
    private static final int X = 20, W = 300;
    private static final int TEXT_H = 10, BAR_H = 10;

    private int textY, barY;
    private int barPos = 0;

    private final SplashScreen splash;
    private Graphics2D graph;

    public SplashController(final int msgXOffset, final int msgYOffset) {
    splash = SplashScreen.getSplashScreen();
    if (splash == null) {
         System.out.println("Error: no splash image specified on the command line");
         return;
    }

   // compute base positions for text and progress bar
   final Dimension splashSize = splash.getSize();
   textY = splashSize.height - msgYOffset;
   barY = splashSize.height - msgYOffset;

   graph = splash.createGraphics();
   //timer.start();
}

public SplashController() {
    this(30, 30);
}

@Override
public void actionPerformed(final ActionEvent e) {
    drawSplashProgress(msg);
}

public void closeSplash() {
    if (splash != null) {
        splash.close();
    }
}

private String msg;

public void drawSplashProgress(final String msg) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            SplashController.this.msg = msg;
            graph.setRenderingHint(RenderingHints.KEY_INTERPOLATION,                              RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            graph.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            graph.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            graph.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

            // clear what we don't need from previous state
            graph.setComposite(AlphaComposite.Clear);

            final FontMetrics fm = graph.getFontMetrics();
            final Rectangle2D textsize = fm.getStringBounds(msg, graph);

            graph.fillRect(X, textY - 1, W, (int) textsize.getHeight() + 5);
            if (barPos == 0) {
                graph.fillRect(X - 3, barY, W + 10, BAR_H);
            }

            // draw new state
            graph.setPaintMode();

            // draw message
            graph.setColor(Color.BLACK);
            graph.drawString(msg, X, textY + TEXT_H);
            try {
                splash.update();
            } catch (final IllegalStateException e) {
               // can be ignored
            }
        }
     });
}

public static void main(final String args[]) throws Exception {
    final SplashController test = new SplashController();
    for (int i = 0; i < 50; i++) {
       test.drawSplashProgress("Progress step number " + i);
       Thread.sleep(250);
    }
    test.closeSplash();
}  
}
说不完的你爱 2024-10-19 14:15:17

Eclipse 启动器在所有平台上都支持此功能,但是转向 SWT 可能太过分了? 此处有详细信息。

The Eclipse launcher supports this functionality on all platforms, but moving to SWT may be going too far? There are details here.

梦太阳 2024-10-19 14:15:17

您可以在脚本中使用 Python(或其他一些公开 GUI 功能的脚本语言)。

http://docs.python.org/faq/gui.html

You could use Python (or some other scripting language that exposes GUI functionality) from your script.

http://docs.python.org/faq/gui.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文