🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Splash Screen

#15521
From: Dan Woods
Date: Thu, 03 Jun 1999 00:00
129 lines
4029 bytes
/*
 * From:  Dan Woods
 * Here's an example from Sun's Q&A pages, modified by me.
 * By default, it looks for test.gif and mylogo.gif
 */
 
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class SplashTest
{
    public static void main(String args[])
    {
       if (args.length > 0)
         new SplashWindowFrame(args[0]);
       else
         new SplashWindowFrame();
    }
}

class SplashWindowFrame extends Frame
{
    SplashWindow sw;
    Image splashImg, frameImg;
    Font theFont;

    SplashWindowFrame()
    {
      // try using an animated gif -- very cool
      this("test.gif");
    }

    SplashWindowFrame(String testImage)
    {
       super();

       /* Add the window listener */
       addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent evt)
          {
              dispose(); 
              System.exit(0);
          }
          });

       /* Size the frame */
       setSize(200,200);

       /* Center the frame */
       Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
       Rectangle frameDim = getBounds();
       setLocation((screenDim.width  - frameDim.width) / 2,
                   (screenDim.height - frameDim.height) / 2);

       MediaTracker mt = new MediaTracker(this);
       splashImg = Toolkit.getDefaultToolkit().getImage(testImage);
       mt.addImage(splashImg, 0);
       try {
          mt.waitForID(0);
       } catch(InterruptedException ie){}

       sw = new SplashWindow(this,splashImg);

       frameImg = Toolkit.getDefaultToolkit().getImage("mylogo.gif");
       mt.addImage(frameImg,0);

       theFont = new Font("Times",Font.BOLD,14);
       try {
          mt.waitForID(0);
       } catch(InterruptedException ie){}
       try {
          // sleeping here for 5 seconds for demo purposes only
          Thread.sleep(5000);
       } catch(InterruptedException ie){}

       sw.dispose();

       /* Show the frame */
       setVisible(true);
    }

    public void paint(Graphics g)
    {
        if (frameImg != null)
          g.drawImage(frameImg,50,30,this);
        g.setColor(Color.black);
        g.setFont(theFont);
        g.drawString("Splash screen is done...", 10, 170);
        g.drawString("...now we have the frame", 10, 185);
    }

    public void update(Graphics g)     { paint(g); }
}

class SplashWindow extends Window
{
    Image splashImg;
    Font theFont;

    SplashWindow(Frame parent, Image img)
    {
      super(parent);
      int width  = 200;
      int height = 200;
      splashImg = img;
      setSize(width, height);

      /* Center the window */
      Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
      Rectangle winDim = getBounds();
      setLocation((screenDim.width - winDim.width) / 2,
              (screenDim.height - winDim.height) / 2);
      theFont = new Font("Times",Font.BOLD,16);
      setVisible(true);
    }
 
    public void paint(Graphics g)
    {
        if (splashImg != null)
          g.drawImage(splashImg,10,10,this);
        g.setColor(Color.black);
        g.setFont(theFont);
        g.drawString("Loading class files...", 20, 130);
        g.drawString("...please wait", 45, 150);
    }

    public void update(Graphics g)       { paint(g); }
}
Technical Details
Message-ID: <3756CBC8.A4A0FDB2@canada.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7ift6p$sm9@forums.borland.com> <MPG.11b5cdd3ce394c439899e9@forums.borland.com> <3752B5F3.73CCA37B@canada.com> <7iua0g$dob20@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,bf0c229ba114cb34
X-Google-Attributes: gidf74b3,public
From: Dan Woods <dwoods@canada.com>
Subject: Re: Splash Screen
Date: 1999/06/03
Message-ID: <3756CBC8.A4A0FDB2@canada.com>
X-Deja-AN: 485336868
Content-Transfer-Encoding: 7bit
References: <7ift6p$sm9@forums.borland.com> <MPG.11b5cdd3ce394c439899e9@forums.borland.com> <3752B5F3.73CCA37B@canada.com> <7iua0g$dob20@forums.borland.com>
Organization: U of Calgary
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language