Splash screen shows blank

B

Blade_runner

Gday

Can someone with a bit of expirence in Java help, i have a class that
call displays my screen in a thread that dies after 8 sec, but my
image does not appear. here is the code. Is the something i am
overlooking?


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JWindow;
import javax.swing.border.LineBorder;


public class splashS extends JWindow {


JPanel screenPane;


/** Creates a new instance of splashS */
public splashS() {

setBackground(Color.WHITE);

}

public void showSplash()
{

JPanel screenPane = (JPanel)getContentPane();
screenPane.setBackground(Color.WHITE);

int width = 450;
int height =115;
Dimension screen =
Toolkit.getDefaultToolkit().getScreenSize();
int x = (screen.width-width)/2;
int y = (screen.height-height)/2;
setBounds(x,y,width,height);

screenPane.setLayout(new FlowLayout());
JLabel label = new JLabel(new ImageIcon("images/
VibrantSplash.jpg"));


screenPane.add(label, BorderLayout.CENTER);
Color oraRed = new Color(156, 20, 20, 255);
screenPane.setBorder(BorderFactory.createLineBorder(oraRed,
10));
setVisible(true);

try
{
Thread.sleep(5000);
}
catch (Exception e)
{
e.printStackTrace();
}

dispose();
}

}
 
A

Andrew Thompson

Blade_runner wrote:

Sub: Splashscreen...

A couple of points about splash screens.
- Java 6 offers inbuilt support for a 'jar splash'.
- Java Web Start offers splash screens from Java 1.2+.
- A splash screen would normally avoid using the
GUI Style 'convenience' classes in Swing, such
as using a JLabel to display the image - the
Swing class (along with all its baggage) can
take a significant time to load.
- It might be the code needs a MediaTracker, but
I vaguely thought JLabel had one built in.

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200707/1
 
R

Roedy Green

Can someone with a bit of expirence in Java help, i have a class that
call displays my screen in a thread that dies after 8 sec, but my
image does not appear. here is the code. Is the something i am
overlooking?

Several problems:

1. the program is incomplete. You never invoke showSplash or start a
thread that does.

2. if you sleep, painting cannot happen, same as wishing your house
would paint while you sleep.

3. Any swing fiddling must be done from the Swing thread.

See http://mindprod.com/jgloss/thread.html
http://mindprod.com/jgloss/swing.html

see http://mindprod.com/jgloss/splash.html
for a code for a splash screen that disappears after X seconds, and
runs on separate thread so loading continues in the background.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top