我想用splashWindow开发一个基本的应用程序。
这应该保持5秒钟,当用户按任意键时,需要重置时间,然后重新定义time()5秒钟。
如果用户不按任何键,则将关闭splashWindow。
public class SplashWindow extends JWindow implements WindowListener, KeyListener
{
private Container c;
SplashWindow()
{
frase1.setText("test");
Font font12 = new Font ("Courier New", Font.BOLD, 18);
frase1.setFont(font12);
frase1.setForeground(Color.WHITE);
frase2.setText("test2");
frase2.setFont(font12);
frase2.setForeground(Color.WHITE);
}
public void open( int tempo )
{
c = getContentPane();
c.setLayout(null);
c.setBackground(Color.black);
Insets in = Toolkit.getDefaultToolkit().getScreenInsets(this.getGraphicsConfiguration());
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int width = d.width-(in.left + in.top);
int height = d.height-(in.top + in.bottom);
this.setSize(width,height);
this.setLocation(in.left,in.top);
BorderLayout layout = new BorderLayout();
c.setLayout(layout);
c.add(BorderLayout.CENTER, frase1);
c.add(BorderLayout.PAGE_END, frase2);
frase1.setHorizontalAlignment(SwingConstants.CENTER);
frase2.setHorizontalAlignment(SwingConstants.CENTER);
this.setVisible( true );
this.addKeyListener(this);
sleep( tempo );
}
/**
* Aguarda um tempo em milisegundos
* @param tempo int que representa o tempo, em milisegundos, que ser�aguardado.
* @exception InterruptedException
* @exception Exception
* @return void
*/
private void sleep( int tempo )
{
try {
Thread.sleep( tempo );
}
catch( InterruptedException ie ) {
ie.printStackTrace();
JOptionPane.showMessageDialog( null, " Erro 00 - Falha no sleep do Splash ", " Erro ", JOptionPane.ERROR_MESSAGE );
}
catch( Exception e ) {
e.printStackTrace();
JOptionPane.showMessageDialog( null, " Erro 00 - Falha no sleep do Splash ", " Erro ", JOptionPane.ERROR_MESSAGE );
}
}
/**
* Fecha a janela de splash
* @return void
*/
public void close()
{
dispose();
}
/**
* @param windowevent
* @return void
*/
public void windowOpened( WindowEvent windowevent )
{
Graphics2D graphics2d = (Graphics2D)getGlassPane().getGraphics();
graphics2d.setColor( new Color( 51, 102, 153 ) );
graphics2d.setFont( new Font( "SansSerif", 0, 16 ) );
}
/**
* @param windowevent
* @return void
*/
public void windowActivated( WindowEvent windowevent )
{
}
/**
* @param windowevent
* @return coid
*/
public void windowClosed( WindowEvent windowevent )
{
}
/**
* @param windowevent
* @return void
*/
public void windowClosing( WindowEvent windowevent )
{
}
/**
* @param windowevent
* @return void
*/
public void windowDeactivated( WindowEvent windowevent )
{
}
/**
* @param windowevent
* @return void
*/
public void windowDeiconified( WindowEvent windowevent )
{
}
/**
* @param windowevent
* @return void
*/
public void windowIconified( WindowEvent windowevent )
{
}
}
最佳答案
使用SplashScreen功能。这是tutorial。
关于java - Eclipse + Java-SplashWindow,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7605709/