Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 加载后启动屏幕打开程序_Java_Awt_Splash Screen - Fatal编程技术网

Java 加载后启动屏幕打开程序

Java 加载后启动屏幕打开程序,java,awt,splash-screen,Java,Awt,Splash Screen,我需要一些帮助,我一直在互联网上寻找代码,对于启动屏幕,我已经找到了一些完美的代码,但有一个问题,我希望启动屏幕在加载完成后打开我的程序,我将如何进行?以下是我的启动屏幕的代码: /* * This demonstration program is released without warranty or restrictions. * You may modify and use it as you wish. * Just don't complain to me if you have t

我需要一些帮助,我一直在互联网上寻找代码,对于启动屏幕,我已经找到了一些完美的代码,但有一个问题,我希望启动屏幕在加载完成后打开我的程序,我将如何进行?以下是我的启动屏幕的代码:

/*
* This demonstration program is released without warranty or restrictions.
* You may modify and use it as you wish.
* Just don't complain to me if you have trouble.
*/
package splashdemo;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.SplashScreen;
import java.awt.geom.Rectangle2D;

/**
* Example for Splash Screen tutorial
* @author Joseph Areeda
*/
public class Main
{
static SplashScreen mySplash;                   // instantiated by JVM we use it to get    graphics
static Graphics2D splashGraphics;               // graphics context for overlay of the splash image
static Rectangle2D.Double splashTextArea;       // area where we draw the text
static Rectangle2D.Double splashProgressArea;   // area where we draw the progress bar
static Font font;                               // used to draw our text

public static void main(String[] args)
{
    splashInit();           // initialize splash overlay drawing parameters
    appInit();              // simulate what an application would do before starting
    if (mySplash != null)   // check if we really had a spash screen
        mySplash.close();   // we're done with it

    // begin with the interactive portion of the program
}
/**
 * just a stub to simulate a long initialization task that updates
 * the text and progress parts of the status in the Splash
 */
private static void appInit()
{
    for (int i = 1; i <= 10; i++)
    {   // pretend we have 10 things to do
        int pctDone = i * 10;       // this is about the only time I could calculate rather than guess progress
        splashText("Configuring Program");     // tell the user what initialization task is being done
        splashProgress(pctDone);            // give them an idea how much we have completed
        try
        {
            Thread.sleep(1000);             // wait a second
        }
        catch (InterruptedException ex)
        {
            break;
        }
    }
}

/**
 * Prepare the global variables for the other splash functions
 */
private static void splashInit()
{
    // the splash screen object is created by the JVM, if it is displaying a splash image

    mySplash = SplashScreen.getSplashScreen();
    // if there are any problems displaying the splash image
    // the call to getSplashScreen will returned null

    if (mySplash != null)
    {
        // get the size of the image now being displayed
        Dimension ssDim = mySplash.getSize();
        int height = ssDim.height;
        int width = ssDim.width;

        // stake out some area for our status information
        splashTextArea = new Rectangle2D.Double(15., height*0.88, width * .45, 32.);
        splashProgressArea = new Rectangle2D.Double(width * .55, height*.92, width*.4, 12 );

        // create the Graphics environment for drawing status info
        splashGraphics = mySplash.createGraphics();
        font = new Font("Dialog", Font.PLAIN, 14);
        splashGraphics.setFont(font);

        // initialize the status info
        splashText("Starting");
        splashProgress(0);
    }
}
/**
 * Display text in status area of Splash.  Note: no validation it will fit.
 * @param str - text to be displayed
 */
public static void splashText(String str)
{
    if (mySplash != null && mySplash.isVisible())
    {   // important to check here so no other methods need to know if there
        // really is a Splash being displayed

        // erase the last status text
        splashGraphics.setPaint(Color.LIGHT_GRAY);
        splashGraphics.fill(splashTextArea);

        // draw the text
        splashGraphics.setPaint(Color.BLACK);
        splashGraphics.drawString(str, (int)(splashTextArea.getX() + 10),(int)(splashTextArea.getY() + 15));

        // make sure it's displayed
        mySplash.update();
    }
}
/**
 * Display a (very) basic progress bar
 * @param pct how much of the progress bar to display 0-100
 */
public static void splashProgress(int pct)
{
    if (mySplash != null && mySplash.isVisible())
    {

        // Note: 3 colors are used here to demonstrate steps
        // erase the old one
        splashGraphics.setPaint(Color.LIGHT_GRAY);
        splashGraphics.fill(splashProgressArea);

        // draw an outline
        splashGraphics.setPaint(Color.BLUE);
        splashGraphics.draw(splashProgressArea);

        // Calculate the width corresponding to the correct percentage
        int x = (int) splashProgressArea.getMinX();
        int y = (int) splashProgressArea.getMinY();
        int wid = (int) splashProgressArea.getWidth();
        int hgt = (int) splashProgressArea.getHeight();

        int doneWidth = Math.round(pct*wid/100.f);
        doneWidth = Math.max(0, Math.min(doneWidth, wid-1));  // limit 0-width

        // fill the done part one pixel smaller than the outline
        splashGraphics.setPaint(Color.GREEN);
        splashGraphics.fillRect(x, y+1, doneWidth, hgt-1);

        // make sure it's displayed
        mySplash.update();
      }
   }

}
/*
*本演示程序的发布不受保修或限制。
*您可以根据需要修改和使用它。
*如果你有麻烦,就别向我抱怨。
*/
包装展示;
导入java.awt.Color;
导入java.awt.Dimension;
导入java.awt.Font;
导入java.awt.Graphics2D;
导入java.awt.SplashScreen;
导入java.awt.geom.Rectangle2D;
/**
*启动屏幕教程示例
*@作者约瑟夫·阿雷达
*/
公共班机
{
静态SplashScreen mySplash;//由JVM实例化,我们使用它来获取图形
静态图形2D splashGraphics;//用于覆盖飞溅图像的图形上下文
静态矩形2D.Double splashTextArea;//我们绘制文本的区域
静态矩形2D.Double splashProgressArea;//绘制进度条的区域
静态字体;//用于绘制文本
公共静态void main(字符串[]args)
{
splashInit();//初始化飞溅覆盖图形参数
appInit();//模拟应用程序在启动前的操作
if(mySplash!=null)//检查我们是否真的有一个spash屏幕
mySplash.close();//我们已经完成了
//从节目的互动部分开始
}
/**
*只是一个存根来模拟一个长的初始化任务
*Splash中状态的文本和进度部分
*/
私有静态void appInit()
{

对于(int i=1;i使用splash demo main方法调用您的程序

public static void main(String[] args)
{
   splashInit();           
   appInit();              
   if (mySplash != null)   
     mySplash.close();   

//call your program here, example HelloWorld.java

HelloWorld hello = new Helloworld();

String[] args = {};
hello.main(args);




}
只需查看..顺便说一句-不要阻止EDT(事件调度线程)-发生这种情况时,GUI将“冻结”。而不是调用
Thread.sleep(n)
为重复任务执行Swing
计时器,或为长时间运行的任务执行
SwingWorker
。有关详细信息,请参阅。