2013-12-15 3 views
0

Мне нужна помощь, я искал в Интернете код, для заставки, я нашел отличный код, но есть одна проблема, я бы хотел, чтобы всплеск экран, чтобы открыть мою программу после того, как она будет загружена, как я буду заниматься этим? Вот код для моей заставки:Программа открытия всплывающих окон после загрузки

/* 
* 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(); 
     } 
    } 

} 
+7

смотреть не дальше, чем [ 'SplashScreen'] (http://docs.oracle. com/javase/7/docs/api/java/awt/SplashScreen.html) .. –

+3

BTW - Не блокируйте EDT (Event Dispatch Thread) - графический интерфейс «замораживается», когда это произойдет. Вместо вызова 'Thread.sleep (n)' реализовать Swing 'Timer' для повторения задач или' SwingWorker' для длительных задач. Подробнее см. [Параллелизм в Swing] (http://docs.oracle.com/javase/tutorial/uiswing/concurrency/). –

ответ

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); 




} 
Смежные вопросы