Hey this is more than likely a very common question, but a question all the
same, I'm creating a splash screen, and have it working ok, As in it
disappears when I click on it but what I want to do is have a timer on it,
so I though I would use thread but....... the embarrassing question.
How can extend JWindow and Threads at the same time?
Here is a timed splash.
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.net.URL;
import javax.swing.JWindow;
import javax.swing.Timer;
/**
* Splash screen shown during program load.
*/
public class Splash extends JWindow implements ActionListener
{
/**
* constructor
*/
Splash()
{
super();
this.getContentPane().setLayout( null );
this.setLocation( 150, 150 );
// size of frame around image
this.setSize( 330, 250 );
this.setBackground ( Config.MATTE_COLOR );
this.setVisible( true );
}
/**
* second stage of initialisation.
* Can't get images until peer created.
*/
public void addNotify()
{
super.addNotify();
URL url = Splash.class.getResource( "images/splash.gif" );
Image splash = this.getToolkit().getImage( url );
JpgViewer j = new JpgViewer( 330, 250, JpgViewer.DOUBLE_BUFFERED
);
j.setBackground ( Config.MATTE_COLOR );
j.setImage( splash );
j.setLocation ( 0, 0 );
this.getContentPane().add ( j );
// allow user to close splash window with just a click
MouseListener closer = new MouseAdapter()
{
/**
* Invoked when the mouse has been clicked on a component.
*/
public void mouseClicked( MouseEvent e )
{
Splash.this.setVisible( false );
Splash.this.dispose();
}
};
this.addMouseListener( closer );
// don't start timing until almost visible.
Timer splashTimer = new Timer( Config.SPLASH_TIME, this );
splashTimer.setRepeats( false );
splashTimer.start();
}
/**
* invoked whenever Timer expires
*
* @param e event not used.
*/
public void actionPerformed( ActionEvent e )
{
setVisible( false );
dispose();
}
/**
* test harness
*
* @param args not used
*/
public static void main ( String[] args )
{
if ( Config.DEBUG )
{
new Splash();
}
}
} // end class Splash.
Instead of JPGViewer you could use a JLabel with IconImage or an
ImageViewer see
http://mindprod.com/products.html#BUS