wrappingduke
03-21-2008, 09:30 PM
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:
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
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:
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