Windows Phone Thoughts - Daily News, Views, Rants and Raves

Check out the hottest Windows Mobile devices at our Expansys store!


Digital Home Thoughts

Loading feed...

Laptop Thoughts

Loading feed...

Android Thoughts

Loading feed...




Go Back   Thoughts Media Forums > WINDOWS PHONE THOUGHTS > Windows Phone Developer

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-21-2008, 09:30 PM
Pupil
Join Date: Mar 2008
Posts: 13
Default how to create splash screen

Hello,

Attempting to create splash screen on Creme Emulator. I'm using JSR-62. I've been able to successfully use this splash screen on J2SE using JDK 1.3.
However, in the emulator the frame of the splash screen is shown but the window w/ the image is not shown until the splash screen is being disposed. That is, the frame is shown and then image flashes and goes away as the frame is being disposed.

The Splash screen is a frame that contains a window and the window has the image. Here's the code I'm using:

Code:
import java.awt.event.*;
import java.awt.*;
import java.net.URL;

publicfinalclass SplashScreen extends Frame {

privatefinal String fImageId;
private MediaTracker fMediaTracker;
private Image fImage;

public SplashScreen(String aImageId) {
/* Implementation Note
   * Args.checkForContent is not called here, in an attempt to minimize 
   * class loading.
   */
if ( aImageId == null || aImageId.trim().length() == 0 ){
thrownew IllegalArgumentException("Image Id does not have content.");
}
   fImageId = aImageId;
}

publicvoid splash(){
   initImageAndTracker();
   setSize(fImage.getWidth(null), fImage.getHeight(null));
   center();

   fMediaTracker.addImage(fImage, 0);
try{
     fMediaTracker.waitForID(0);
}
catch(InterruptedException ie){
     System.out.println("Cannot track image load.");
}

   SplashWindow splashWindow = new SplashWindow(this,fImage);
}

privatevoid initImageAndTracker(){
   fMediaTracker = new MediaTracker(this);
   URL imageURL = SplashScreen.class.getResource(fImageId);
   fImage = Toolkit.getDefaultToolkit().getImage(imageURL);
}

privatevoid center(){
   Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
   Rectangle frame = getBounds();
   setLocation((screen.width - frame.width)/2, (screen.height - frame.height)/2);
}

privateclass SplashWindow extends Window {
private Image fImage;

   SplashWindow(Frame aParent, Image aImage) {
super(aParent);
      fImage = aImage;
      setSize(fImage.getWidth(null), fImage.getHeight(null));
      Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
      Rectangle window = getBounds();
      setLocation((screen.width - window.width) / 2, (screen.height - window.height) / 2);
      setVisible(true);
}
publicvoid paint(Graphics graphics) {
if (fImage != null) {
       graphics.drawImage(fImage,0,0,this);
}
}
}

/**
 * Developer test harness shows the splash screen for a fixed length of 
 * time, without launching the full application.
 */
privatestaticvoid main(String[] args){
   SplashScreen splashScreen = new SplashScreen("images/StocksMonitor.gif");
   splashScreen.splash();
try{
     Thread.sleep(2000);
}
catch(InterruptedException ex) {
     System.out.println(ex);
}
   splashScreen.dispose();
}
}

//Here is an example of a class which launches an application using the above SplashScreen 
publicstaticvoid main(String args[]) {
fSplashScreen = new SplashScreen("images/MyImage.gif");
fSplashScreen.splash();

try
{
Thread.sleep(2000);
}
catch(.....){}

java.awt.EventQueue.invokeLater(new Runnable() {
publicvoid run() {
fSplashScreen.dispose()
}
});



any help is appreciated
 
Reply With Quote
  #2 (permalink)  
Old 05-15-2008, 10:13 AM
Neophyte
Join Date: May 2008
Posts: 3

Aha ! A Java Buddy that uses Creme too (You should know Rene, right ? haha), and using the same splash screen tutorial also ! What a coincidence, lol

Anyway, i tried the splash screen tutorial also, to find out that the splashing just shows for a while like your experience.

I tried several things, and found out that to achieve the purpose of showing it till the main frame is 'realized' (shown and drawed on screen), i have to put the line SplashWindow.dispose() in the main method in my main app class.

In my case, it is like this :

public static void main(String[] args) {
// load JNI stuffs code

java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MySwingApp().setVisible(true);
SplashWindow.dispose();
}
});

// set the app to foreground code
}

Good luck buddy !

Cheers,
Albert Kam
 
Reply With Quote
  #3 (permalink)  
Old 06-24-2008, 06:35 PM
Pupil
Join Date: Mar 2008
Posts: 13
Default how to create splash screen

Hi Albert,

Thx. for the response. I apologize for the belated response(well over a month, now). I've going between different projects.

I've tried what you have suggested, i.e. placing the call to dispose() after run() call and I ended up w/ the same results. That is, the frame is shown w/out the image.

However, I did pause the splashwindow thread by invoking wait() and of course, the image was then visible in the frame. It appears the image does not have a chance to paint in the frame, so I tried overriding the update method, so repaint() could be called and subsequently paint. Unfortunately, did not work either.

Any suggestions are appreciated.

Kind regards,

Jim
 
Reply With Quote
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

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


LinkBacks (?)
LinkBack to this Thread: http://forums.thoughtsmedia.com/f415/how-create-splash-screen-88233.html
Posted By For Type Date
Pocket PC Thoughts - Daily News, Views, Rants and Raves This thread Refback 06-27-2008 09:34 AM


All times are GMT +1. The time now is 09:40 AM.



Search Engine Friendly URLs by vBSEO 3.6.0