Captain's Universe Home
Captain's Universe Home
Cosmic Ray Muon DetectorTeleGarden Pages
Time on MarsBryophyllum Plants
Jupiter Radio AstronomyAncient Pages
Salzburg Tourist GuideEarth Magnetometer
  H O M E     AJAX & MORE     LINUX & MORE     RTAI     XENOMAI     ADEOS IPIPE      
    JAVA & BROWSERS     *NIX     ELECTRONICS     REVIEWS     ARTEMIA     FAIRY SHRIMP      



Java Application Template GUI Tutorial Part 2/5 - How to make an executable JAR file

In PART 1 we have created the Splash-class, which will use the SplashWindow-class. SplashWindow displays the splash screen, and is responsible for removing the splash image when the main-class is loading and executing.



SplashWindow.java:
// JAVA Application Template (C) 2005 www.captain.at
// class SplashWindow: A class for displaying the splash screen

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

public class SplashWindow extends Window {
	private Image splashImage;
	private boolean paintCalled = false;
	public SplashWindow(Frame owner, Image splashImage) {
		super(owner);
		this.splashImage = splashImage;
		MediaTracker mt = new MediaTracker(this);
		mt.addImage(splashImage,0);
		try {
			mt.waitForID(0);
		} catch(InterruptedException ie) {}
		int imgWidth = splashImage.getWidth(this);
		int imgHeight = splashImage.getHeight(this);  
		setSize(imgWidth, imgHeight);
		Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
		setLocation( (screenDim.width - imgWidth) / 2, 
				(screenDim.height - imgHeight) / 2 );
	}

	public void update(Graphics g) {
		g.setColor(getForeground());
		paint(g);
	}

	public void paint(Graphics g) {
		g.drawImage(splashImage, 0, 0, this);
		if (! paintCalled) {
			paintCalled = true;
			synchronized (this) { notifyAll(); }
		}
	}

	public static Frame splash(Image splashImage) {
		Frame f = new Frame();
		SplashWindow w = new SplashWindow(f, splashImage);
		w.toFront();
		w.show();
		if (! EventQueue.isDispatchThread()) {
			synchronized (w) {
				while (! w.paintCalled) {
					try {
						w.wait();
					} catch (InterruptedException e) {}
				}
			}
		}
		return f;
	}
}




PART 1 PART 2 PART 3 PART 4 PART 5


Last-Modified: Sat, 04 Feb 2006 16:03:10 GMT

Google
 
Web www.captain.at
go to top
© 1996-2010 . All rights reserved.
No reproduction, distribution, publishing or transmission of the copyrighted materials at this site is permitted. Policy
go to top