Solved

Splash (logo) screen in Java

Posted on 2000-03-26
1
302 Views
Last Modified: 2012-05-04
How to display an application logo screen (a rectangular graphic) in Java? From what I know every Java application must start with a frame but I need to start it with some kind of container with no buttons or titlebars but with an image inside.
0
Comment
Question by:mrmind3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 2

Accepted Solution

by:
stalefish earned 100 total points
ID: 2659369
I found this at http://www.tactika.com/realhome/realhome.html

import java.awt.*;
 import java.awt.event.*;

 public class Splash extends Window {
   private Image splashImage;
   private int imgWidth, imgHeight;
   private String imgName;
   private static final int BORDERSIZE = 5;
   private static final Color BORDERCOLOR = Color.blue;
   Toolkit tk;
 
   public Splash(Frame f, String imgName) {
     super(f);
     this.imgName = imgName;
     tk = Toolkit.getDefaultToolkit();
     splashImage = loadSplashImage();
     showSplashScreen();
     f.addWindowListener(new WindowListener());
     }
   public Image loadSplashImage() {
     MediaTracker tracker = new MediaTracker(this);
     Image result;
     result = tk.getImage(imgName);
     tracker.addImage(result, 0);
     try {
       tracker.waitForAll();
       }
     catch (Exception e) {
       e.printStackTrace();
       }
     imgWidth = result.getWidth(this);
     imgHeight = result.getHeight(this);
     return (result);
     }

   public void showSplashScreen() {
     Dimension screenSize = tk.getScreenSize();
     setBackground(BORDERCOLOR);
     int w = imgWidth + (BORDERSIZE * 2);
     int h = imgHeight + (BORDERSIZE * 2);
     int x = (screenSize.width - w) /2;
     int y = (screenSize.height - h) /2;
     setBounds(x, y, w, h);
     setVisible(true);
     }

   public void paint(Graphics g) {
     g.drawImage(splashImage, BORDERSIZE, BORDERSIZE,
       imgWidth, imgHeight, this);
     }

   class WindowListener extends WindowAdapter {
     public void windowActivated(WindowEvent we) {
       setVisible(false);
       dispose();
       }
     }
   }


The following example use this image  (jht.gif) as the splash image.

 import java.awt.*;
 import java.awt.event.*;

 public class TestSplash {
   MyFrame theFrame;
   
   
   public static void main (String args[]){
     TestSplash t = new TestSplash();
     t.createMainFrame();
     }
     
   private void createMainFrame() {
     theFrame = new MyFrame("A Dummy Frame");  
     theFrame.setVisible(true);
     }

 }

 class MyFrame extends Frame {
   Splash mySplash;
   public MyFrame(String title){
     super(title);
     addWindowListener
       (new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
           System.exit(0);
           }
         }
        );
     mySplash = new Splash(this, "jht.gif");
     
     // dummy delay so we can see the Splash!
     for(int i = 0; i < 3000; i++) {
       System.out.println(i) ;
       }
     setSize(200,200);
     }      
   }
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Is there a simpler dropbox system? 10 53
Java List 4 76
Which is best Image Resizing Web service 11 42
Setup Eclipse for Andriod development 2 21
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question