日食 + Java-SplashWindow

发布于 2024-12-07 02:00:07 字数 3444 浏览 0 评论 0原文

我想用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

分開簡單 2024-12-14 02:00:07

使用 SplashScreen 功能。这是一个教程

Use SplashScreen Functionality. Here is a tutorial.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文