How do I get my Java demo application to display an image before it starts?

I am using NetBeans IDE 6.8 (Mac version). What tool will their GUI creator help me with this?

I want to show the user an image while my application loads for several seconds before I show him the application. How can i do this? initialization

+3
source share
4 answers

If you have Java 6 installed, check out the splash screen tutorial .

+9
source

, -splash java... , splash.jpg main.class,

,

java -splash: pathoftheimage/splash.jpg main

+5

MAC-, , , Java 6, . , ( , ).

JDialog dlg = new JDialog();
// Remove dialog decorations to make it look like a splashscreen.
dlg.setUndecorated(true);
dlg.setModal(true);
dlg.setLayout(new BorderLayout());
// Load image.
ImageIcon img = new ImageIcon(getClass().getResource("/foo/bar/splash.png");
// Add image to center of dialog.
dlg.add(img, BorderLayout.CENTER);
dlg.setLocationRelativeTo(null);
dlg.setVisible(true);

// ... Perform application initialisation here.

// Initialisation complete so hide dialog.
dlg.setVisible(false);
dlg = null;
+3

NetBeans..., , NetBeans .

  • Right Click Project .
  • properties
  • Application
  • Splash Screen, Browse , .

enter image description here

enter image description here

When you do this, yours imagewill show, but you cannot see it. To see this, you must delay time appearence next window. To do this, follow these steps.

  • Go to the area JFrame codeyou want to show next.
  • The Main Funwill be runfun.
  • Inside the function, runjust write the following code.

    attempt {

    Thread.sleep (time in milliseconds is exactly the same as 4200);

    // Create Next Frame Object Here }

    catch (Exception ex) {}

-1
source

Source: https://habr.com/ru/post/1732136/


All Articles