我需要一些帮助,我一直在互联网上查找代码,对于启动画面,我发现了一些完美的代码,但是有一个问题,我希望启动画面后打开我的程序它已完成加载,我该怎么做呢?这是我的启动画面的代码:
/*
* 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();
}
}
}
答案 0 :(得分:0)
使用你的启动演示主方法调用你的程序,
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);
}