日食 + Java-SplashWindow
我想用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 )
{
}
}
I would like develop a basic application with splashWindow.
this should stay for 5 seconds, when user press any key, the time is need reset, and redefine the time() for 5 seconds again.
If user dont press any key, the splashWindow close.
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 )
{
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 SplashScreen 功能。这是一个教程。
Use SplashScreen Functionality. Here is a tutorial.