tags:

views:

181

answers:

1

I'm using NetBeans 6.1 as my primary IDE, in there I can't run this splash screen example which have given by the Sun (It throws an nullpointerExeption). But I can run this on command line using this arguments.

java -splash:filename.gif SplashDemo

I dont know how to inject command line arguments in NetBeans. Please someone help.

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

}

+1  A: 

Go to project properties (right click on a project, and choose properties). Choose "run" item from the Categories list. There you can setup the arguments, VM options etc.

Senad Uka
Thanks but i know this already this is about for the whole project, I'm asking for a single class.
MMRUser
+1: works for me (under Eclipse) if I set the VM args correctly (ie. the -splash:imgfilename) I'm not sure we understand what you mean by "I'm asking for a single class". The splash screen is for loading the entire JVM + your app. I don't think you can get it to pop up while your app is already running.
Trevor Harrison