Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2007

Tip: Looking for answers? Try searching our database.

Splash screen shows blank

Thread view: 
Blade_runner - 06 Jul 2007 08:49 GMT
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();
   }

}
Andrew Thompson - 07 Jul 2007 01:51 GMT
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.

Signature

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

Roedy Green - 07 Jul 2007 07:25 GMT
On Fri, 06 Jul 2007 00:49:43 -0700, Blade_runner
<tbsetlalekgosi@gmail.com> wrote, quoted or indirectly quoted someone
who said :

>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.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.