Then you can have a splash screen class that implements Runnable that looks like this
/**
* $Id$
*
* (c) 2004 Swizel Studios.
*/
package com.swizel.manlymayhem;
import java.io.FileNotFoundException;
import java.io.IOException;
import com.swizel.RenderListener;
import com.swizel.LogicListener;
import com.swizel.exceptions.ResourceNotLoadedException;
import com.swizel.exceptions.ResourceNotFoundException;
import com.swizel.utils.FontUtils;
import com.swizel.utils.ResourceUtils;
import com.swizel.utils.TextureUtils;
import com.swizel.awt.GLComponent;
import static org.lwjgl.opengl.GL11.*;
import org.lwjgl.opengl.Display;
import org.lwjgl.util.vector.Vector2f;
/**
* Splash screen, which will load resources while displaying a picture and progress bar.
*
* @author $author$
* @version $revision$
*/
public class Splash implements RenderListener, LogicListener, Runnable {
private boolean finishedLoading = false;
private boolean removeListener = false;
private int percentagePixelWidth = Main.SCREEN_WIDTH / 100;
/**
* Default constructor.
*
*/
public Splash() {
}
/**
* This method starts a new thread and waits for the splash screen images to be loaded.
*/
public void init() {
new Thread(this).start();
boolean splashLoaded = false;
while (!splashLoaded) {
try {
Thread.yield();
ResourceUtils.getResource("images.splash.background");
splashLoaded = true;
} catch (ResourceNotFoundException rnfe) {
// loading has finished, but splash wasn't found.
splashLoaded = true;
} catch (ResourceNotLoadedException rnle) {
// do nothing here, perhaps timeout.
// System.out.println("waiting for images.splash.background to load.");
}
}
FontUtils.init();
}
/**
* When the resources have been loaded the splash screen is no longer needed,
* this method initialises the next part of the game.
*/
public void destroy() {
Main.addListener(new Camera());
Main.addListener(new SkyDome());
Main.addListener(new Terrain());
Main.addListener(new City());
Main.addListener(new Sun());
Main.addListener(new HUD());
}
/**
* Handle the logic for the splash screen, i.e. flagging when loading of resources is finished.
*/
public void logic() {
if (removeListener) {
Main.removeListener(this);
}
if (finishedLoading) {
removeListener = true;
}
}
/**
* Return the number of triangles rendered in the previous frame by this component.
* @return The number of triangles.
*/
public int getTriangleCount() {
return 0;
}
/**
* Render the splash screen and progress bar.
*/
public void render() {
int percentComplete = ResourceUtils.getloadResourcesProgress();
Display.setTitle("Loading resources : " + percentComplete + "%");
// Now display splash screen and progress bar while other resources are loaded.
GLComponent.setProjectionMode();
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBindTexture(GL_TEXTURE_2D, TextureUtils.getTexture("images.splash.background"));
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(0, 0);
glTexCoord2f(1, 0); glVertex2i(800, 0);
glTexCoord2f(1, 1); glVertex2i(800, 600);
glTexCoord2f(0, 1); glVertex2i(0, 600);
glEnd();
glDisable(GL_TEXTURE_2D);
// The progress bar background.
glPushMatrix();
glColor3f(0f, 0f, 0f);
glRecti(0, 19, 800, 29);
// The progress bar.
glColor3f(0.5f, 0.5f, 0.5f);
glRecti(0, 20, percentComplete * percentagePixelWidth, 28);
// The progress bar highlight.
glColor3f(0.75f, 0.75f, 0.75f);
glRecti(0, 26, percentComplete * percentagePixelWidth, 27);
glPopMatrix();
GLComponent.restoreProjectionMode();
Thread.yield();
}
/**
* Seperate thread for loading resources using the resource manager.
*/
public void run() {
try {
ResourceUtils.loadResources("data/resources.dat");
} catch (ResourceNotLoadedException rnle) {
System.out.println("1" + rnle);
} catch (FileNotFoundException fnfe) {
System.out.println("2" + fnfe);
} catch (IOException ioe) {
System.out.println("3" + ioe);
} finally {
finishedLoading = true;
}
}
} // class
/**
* Changelog
* ---------
* $log$
*
*/