I am getting inconsistant results when I try to create a Splash Screen. Here are the two versions of what I get:


Basically this is what I am doing:
-=Main Class=-
public TextTest()
{
splashThread = new Thread(new SplashTest(3, progressString, this));
splashThread.start();
progressString = "CreateScreenManager"
screen = new ScreenManager("TextureTester",WIDTH,HEIGHT,fullscreen,vsync);
progress++;
progressString = "Creating Font";
text = new FontTranslator(fontname, fontstyle, fontsize);
progress++;
progressString = "Setting ZMatch";
text.setZMatch(45.0f, HEIGHT);
progress++;
splashThread = null;
startloop();
}
-=Splash Class=-
public class SplashTest extends JFrame implements Runnable
{
private Image splashImage;
private JPanel imagePanel;
private JProgressBar progressBar;
public SplashTest(int maxProgress, String initialString)
{
setUndecorated(true);
setBackground(Color.BLACK);
setResizable(false);
setSize(640, 261);
setAlwaysOnTop(true);
Container box = getContentPane();
box.setLayout(new BorderLayout());
splashImage = getToolkit().createImage("Splash.jpg");
MediaTracker mediaTracker = new MediaTracker(this);
mediaTracker.addImage(splashImage, 0);
try
{
mediaTracker.waitForID(0);
}
catch (InterruptedException ie)
{
System.err.println(ie);
System.exit(1);
}
imagePanel = new JPanel();
imagePanel.setSize(splashImage.getWidth(null), splashImage.getHeight(null));
box.add(imagePanel, BorderLayout.CENTER);
progressBar = new JProgressBar(JProgressBar.HORIZONTAL, 0, maxProgress);
progressBar.setBackground(Color.BLACK);
progressBar.setForeground(new Color(128, 0, 0));
progressBar.setStringPainted(true);
progressBar.setString(initialString);
progressBar.setBorderPainted(false);
box.add(progressBar, BorderLayout.SOUTH);
setVisible(true);
imagePanel.getGraphics().drawImage(splashImage, 0, 0, null);
}
public void run()
{
Thread myThread = Thread.currentThread();
while (parent.splashThread == myThread)
{
progressBar.setValue(parent.progress);
progressBar.setString(parent.progressString);
try
{
Thread.sleep(1);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
}
dispose();
}
}