2013-02-18 71 views
0

在我的節目,我想用一個啓動畫面幾秒鐘啓動它,然後開始我的程序的第一幀...閃屏沒有出現圖像

但也有2個問題。

首先出現閃屏,但它顯示沒有出現

二時飛濺結束了本來的照片,第一幀被啓動,但事實並非如此。

這是我的代碼.....所以我需要知道是什麼問題?

public class Splash extends JWindow { 

    AbsoluteLayout absoluto; 
    AbsoluteConstraints absimage,absrra; 
    ImageIcon Image; 
    JLabel jlabel; 
    JProgressBar Barra; 
    public Splash(){ 
     absoluto=new AbsoluteLayout(); 
     absimage = new AbsoluteConstraints(0,0); 
     absrra = new AbsoluteConstraints(0,410); 
     jlabel=new JLabel(); 
     Image=new ImageIcon("sales.png"); 
     jlabel.setIcon(Image); 
     Barra=new JProgressBar(); 
     Barra.setPreferredSize(new Dimension(410,10)); 
     this.getContentPane().setLayout(absoluto); 
     this.getContentPane().add(jlabel,absimage); 
     this.getContentPane().add(Barra,absrra); 
     new Thread(){ 
      public void run(){ 
       int i=0; 
       while(i<101){ 
        Barra.setValue(i); 
        i++; 
        try { 
         sleep(30); 
        } catch (InterruptedException ex) { 
         // Logger.getLogger(Splash.class.getName()).log(Level.SEVERE,null,ex); 
        } 
       } 
       System.exit(0); 
      } 
     }.start(); 
     this.pack(); 
     this.setLocationRelativeTo(null); 
     this.setVisible(true); 
    } 

    public static void main (String args[]) throws SQLException, ClassNotFoundException{ 
     new Splash(); 
     loginForm a =new loginForm(); 
     a.setTitle("fram 1"); 
     a.setSize(700,600); 
     a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     a.setLocationRelativeTo(null); 
     a.setVisible(true); 
    } 
} 
+0

你可以首先看看[this](http://stackoverflow.com/questions/14915022/why-wont-this-draw-the-image/14915370#14915370)和[this](http:// stackove rflow.com/questions/14802662/splash-screen-progress-bar-not-drawing/14803941#14803941)幾個例子 – MadProgrammer 2013-02-18 06:02:00

回答

2

不知道更多,我會說你有問題的組合...

首先,這...

Image=new ImageIcon("sales.png"); 

ImageIcon(String)期望一個文件(從本地磁盤),這裏你說圖像必須存在於執行程序的同一個目錄中。如果圖像是嵌入式資源,您將遇到麻煩。您需要提供URL

其次,我不知道什麼AbsoluteLayout是什麼,但我懷疑這是一種方便的方式說和沒有證據給國家,我會懷疑你沒有提供任何寬度/高度信息的標籤,意思是0x0。

有關使用JLabel作爲其他組件的後備容器的示例,可以參考this

您也在通過更新EDT外側的進度條來違反Swing的單線程規則。這是一個很大的,不,不。你實際上會更好地使用SwingWorker。請致電Concurrency in Swing瞭解更多詳情。

以下幾個不同的相同問題的例子。

在回答你問題的第二部分...

我需要很長的硬看看System.exit(0); ...