Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-27-2008, 08:40 PM
Moderator
 
Join Date: Nov 2007
Posts: 1,637
Java Tip will become famous soon enoughJava Tip will become famous soon enough
A simple Splash screen
Code:
import java.awt.Color; import java.awt.*; import java.awt.Graphics; import java.awt.MediaTracker; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JWindow; /** A simple Splash screen. */ public class Splash extends JWindow { protected ImageIcon im; public Splash(JFrame f, String progName, String fileName) { super(); // Can't use Swing border on JWindow: not a JComponent. // setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); im = new ImageIcon(fileName); if (im.getImageLoadStatus() != MediaTracker.COMPLETE) JOptionPane.showMessageDialog(f, "Warning: can't load image " + fileName + "\n" + "Please be sure you have installed " + progName + " correctly", "Warning", JOptionPane.WARNING_MESSAGE); int w = im.getIconWidth(), h = im.getIconHeight(); setSize(w, h); UtilGUI.center(this); addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { dispose(); } }); addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent e) { dispose(); } }); } public void paint(Graphics g) { im.paintIcon(this, g, 0, 0); g.setColor(Color.green); g.drawRoundRect(0, 0, getWidth()-1, getHeight()-1, 7, 7); } } class UtilGUI { /** Centre a Window, Frame, JFrame, Dialog, etc. */ public static void centre(Window w) { // After packing a Frame or Dialog, centre it on the screen. Dimension us = w.getSize(), them = Toolkit.getDefaultToolkit() .getScreenSize(); int newX = (them.width - us.width) / 2; int newY = (them.height - us.height) / 2; w.setLocation(newX, newY); } /** * Center a Window, Frame, JFrame, Dialog, etc., but do it the American * Spelling Way :-) */ public static void center(Window w) { UtilGUI.centre(w); } /** Maximize a window, the hard way. */ public static void maximize(Window w) { Dimension us = w.getSize(), them = Toolkit.getDefaultToolkit() .getScreenSize(); w.setBounds(0, 0, them.width, them.height); } }
__________________
Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums! (closes on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Take a screen shot oasis New To Java 0 05-24-2008 08:57 PM
Help with a very simple method for a very simple beginner. cakeman New To Java 2 05-04-2008 06:27 PM
new screen tha_crazy New To Java 2 08-15-2007 10:30 AM
Connecting a splash screen to a code : HELP !!! mobeenkhan NetBeans 0 08-02-2007 06:15 PM
Full screen Jack Advanced Java 2 07-02-2007 06:49 AM


All times are GMT +3. The time now is 12:58 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org