2009-08-14 5 views
1

NetBeans 6.1을 기본 IDE로 사용하고 있습니다. Sun에서 제공 한이 스플래시 화면 예제를 실행할 수 없습니다 (nullpointerExeption을 발생 시킴). 하지만이 인수를 사용하여 명령 줄에서 실행할 수 있습니다.Java SplashScreen

자바 -splash : SplashDemo

내가 넷빈즈에 명령 줄 인수를 주입하는 방법을 잘 모릅니다

filename.gif. 제발 누군가 도와주세요.

import java.awt.*; 
import java.awt.event.*; 

public class SplashDemo extends Frame implements ActionListener { 

    static void renderSplashFrame(Graphics2D g, int frame) { 
     final String[] comps = {"foo", "bar", "baz"}; 
     g.setComposite(AlphaComposite.Clear); 
     g.fillRect(120, 140, 200, 40); 
     g.setPaintMode(); 
     g.setColor(Color.BLACK); 
     g.drawString("Loading " + comps[(frame/5) % 3] + "...", 120, 150); 
    } 

    public SplashDemo() { 
     super("SplashScreen demo"); 
     setSize(300, 200); 
     setLayout(new BorderLayout()); 
     Menu m1 = new Menu("File"); 
     MenuItem mi1 = new MenuItem("Exit"); 
     m1.add(mi1); 
     mi1.addActionListener(this); 
     this.addWindowListener(closeWindow); 

     MenuBar mb = new MenuBar(); 
     setMenuBar(mb); 
     mb.add(m1); 
     final SplashScreen splash = SplashScreen.getSplashScreen(); 
     if (splash == null) { 
      System.out.println("SplashScreen.getSplashScreen() returned null"); 
      return; 
     } 
     Graphics2D g = splash.createGraphics(); 
     if (g == null) { 
      System.out.println("g is null"); 
      return; 
     } 
     for (int i = 0; i < 100; i++) { 
      renderSplashFrame(g, i); 
      splash.update(); 
      try { 
       Thread.sleep(90); 
      } catch (InterruptedException e) { 
      } 
     } 
     splash.close(); 
     setVisible(true); 
     toFront(); 
    } 

    public void actionPerformed(ActionEvent ae) { 
     System.exit(0); 
    } 
    private static WindowListener closeWindow = new WindowAdapter() { 

     public void windowClosing(WindowEvent e) { 
      e.getWindow().dispose(); 
     } 
    }; 

    public static void main(String args[]) { 
     SplashDemo test = new SplashDemo(); 
    } 
} 
+0

예외는 어디에서 발생합니까? – Zed

+0

스플래시 화면이 Eclipse에서 작동합니까? –

답변

1

프로젝트 속성 (프로젝트를 마우스 오른쪽 단추로 클릭하고 속성 선택)로 이동하십시오. 범주 목록에서 "실행"항목을 선택하십시오. 인수, VM 옵션 등을 설정할 수 있습니다.

+0

고마워요.하지만 이건 이미 전체 프로젝트에 관한 것이고, 나는 하나의 클래스를 요구하고 있습니다. – Switch

+0

+1 : VM 인수를 올바르게 설정하면 (Eclipse의 경우) 작동합니다 (예 : -splash : imgfilename). "단일 클래스를 요청합니다"라는 의미를 이해하지 못했습니다. 시작 화면은 전체 JVM과 앱을로드하기위한 화면입니다. 앱이 이미 실행되는 동안 팝업을 표시 할 수 있다고 생각하지 않습니다. –

관련 문제