🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #16779

Re: Splash Screen

#16779
From: Edoardo Comar
Date: Tue, 19 Jan 1999 00:00
157 lines
4198 bytes
Jonathan wrote in message <77v2lk$9384@forums.borland.com>...
>How do i make a startup splash screen for my java application?


here you go, but, please,
bear my comments in Italian ...

Edo.

============================================================
import java.beans.*;
import java.awt.*;
import java.net.*;

import com.sun.java.swing.*;
import com.sun.java.swing.border.*;

/**
 * SplashWindow :
 * NB: nel designer compare con una titleBar, a run-time comunque non c'e'!
 *
 * Esempio d'uso:
 *
 *   //prima istruzione di un'applicazione java :
 *   SplashWindow splashWindow = new
SplashWindow("/package/subpackage/splashScreen.gif");
 *   splashWindow.setVisible(true);
 *   //... perform initialization
 *   splashWindow.setVisible(false);
 *   mainFrame.setVisible(true);
 */
public class SplashWindow
extends JWindow
{
  BorderLayout borderLayout1 = new BorderLayout();
  JLabel jLabel1 = new JLabel();
  private String imageFileName;
  private String text;

  /**
   * bean constructor
   */
  public SplashWindow(String anImageFileName)
  {
    this();
    setImageFileName(anImageFileName);
  }

  public SplashWindow()
  {
    super();
    try
    {
      jbInit();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }




  private void jbInit() throws Exception
  {
    this.getContentPane().setLayout(borderLayout1);
    jLabel1.setBorder(BorderFactory.createRaisedBevelBorder());
    jLabel1.setAlignmentX(SwingConstants.CENTER);
    jLabel1.setAlignmentY(SwingConstants.CENTER);
    jLabel1.setHorizontalTextPosition(SwingConstants.CENTER);
    this.getContentPane().add(jLabel1, BorderLayout.CENTER);
  }


  //override
  public void setVisible(boolean visible)
  {
    // se non e' ancora stata settata un'immagine ne' un testo
    // mostro comunque il nome di questa classe.
    if(visible == true && imageFileName==null && text==null)
      this.setText(this.getClass().getName());

    super.setVisible(visible);
  }

  /**
   * property imageFileName
   * richiede il nome di un file immagine
   * nome Fully Qualified rispetto al classpath.
   * (es. "/it/tecnest/fx/flex.gif")
   *
   */
  public void setImageFileName(String newImageFileName)
  {
    try
    {
      imageFileName = newImageFileName;
      URL _url = this.getClass().getResource(newImageFileName);
      jLabel1.setText("");
      jLabel1.setIcon(new ImageIcon(_url));
    }
    catch(Exception exc)
    {
      this.setText(newImageFileName);
    }
    pack();
    centerOnScreen();
  }

  /**
   * property imageFileName
   */
  public String getImageFileName()
  {
    return imageFileName;
  }

  /**
   * property text : alternativa all'immagine
   */
   public void setText(String aString)
   {
      text = aString;
      jLabel1.setFont(new Font("Dialog", 1, 20));
      jLabel1.setForeground(Color.blue);
      jLabel1.setText(aString);
      pack();
      centerOnScreen();
   }

  /**
   * property text
   */
   public String getText()
   {
      return text;
   }

//--------------------------------------------

  private void centerOnScreen()
  {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension splashWindowSize = getSize();
    if (splashWindowSize.height > screenSize.height) {
      splashWindowSize.height = screenSize.height;
    }
    if (splashWindowSize.width > screenSize.width) {
      splashWindowSize.width = screenSize.width;
    }
    setLocation((screenSize.width  - splashWindowSize.width)  / 2,
                (screenSize.height - splashWindowSize.height) / 2);
  }


}
Technical Details
Message-ID: <7827eb$btb5@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <77v2lk$9384@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,9da3f5e89cdb9fa3
X-Google-Attributes: gidf74b3,public
From: "Edoardo Comar" <comar@tecnest.it>
Subject: Re: Splash Screen
Date: 1999/01/19
Message-ID: <7827eb$btb5@forums.borland.com>
X-Deja-AN: 434428351
References: <77v2lk$9384@forums.borland.com>
X-Mimeole: Produced By Microsoft MimeOLE V4.72.3110.3
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.language