| | |
splash screen woes
![]() |
Hi people, I am having trouble with my splash screen. Basically, it just flashes really quickly and I can't get to to pause for long enough. See attached file.
I've attached my program as a zipped file.
After you have download it you need to right click and extract it otherwise it won't work.
Awaiting your earliest reply.
God bless.
Here's the code:
I've attached my program as a zipped file.
After you have download it you need to right click and extract it otherwise it won't work.
Awaiting your earliest reply.
God bless.
Here's the code:
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, "blart.png");
// dummy delay so we can see the Splash!
for(int i = 0; i < 50000; i++) { //PROBLEM HERE
System.out.println(i) ;
}
setSize(200,200);
}
} *Voted best profile in the world*
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
It'll make a huge difference.
It's not tested, but if you simply want a delay then use threads.
Java Syntax (Toggle Plain Text)
class Test implements Runnable { public Test() { super(); Thread t = new Thread(this); t.start(); //t.run(); can't remember if you have to call this or not } public void run() { while (true) { try { System.out.println("In Run"); Thread.sleep(2000); } catch(InterruptedException ie) { } } } }
It's not tested, but if you simply want a delay then use threads.
•
•
•
•
Originally Posted by server_crash
It'll make a huge difference.
Java Syntax (Toggle Plain Text)
class Test implements Runnable { public Test() { super(); Thread t = new Thread(this); t.start(); //t.run(); can't remember if you have to call this or not } public void run() { while (true) { try { System.out.println("In Run"); Thread.sleep(2000); } catch(InterruptedException ie) { } } } }
It's not tested, but if you simply want a delay then use threads.
Here is the other part of the code. Please try it or see attachment for an example. Do you see what I mean?
Java Syntax (Toggle Plain Text)
//Splash.java 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 = 0; private static final Color BORDERCOLOR = Color.WHITE; 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 { // was windowActivated, thanks to H.Grippa for the fix! public void windowOpened(WindowEvent we) { setVisible(false); dispose(); } } }
Java Syntax (Toggle Plain Text)
//TestSplash.java 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); } } ); //file needs to be jpeg or png mySplash = new Splash(this, "blart.png"); Thread.sleep(2000); // dummy delay so we can see the Splash! //for(int i = 0; i < 50000; i++) { //System.out.println(i) ; //} setSize(200,200); } }
*Voted best profile in the world*
•
•
•
•
Originally Posted by server_crash
That won't work the way you have. You MUST implement Runnable and override the run() method. Inside the run method is where you create the delay.
I mean to say, it works on my computer but fails to work on my friends computer. Has anyone else tried it? And I know she has Java run time environment on hers but some appears to be wrong.
Please try my code. The main class is TestSplash.java
Thanks again,your help is appreciated...
*Voted best profile in the world*
•
•
•
•
Originally Posted by server_crash
I got a frame called a dummy frame, but that was it. Nothing was on the frame or anything. Is your friend recieving an error message? Does the console icon appear in the system tray?
For example
Java Syntax (Toggle Plain Text)
mySplash = new Splash(this, "blart.png");
would be changed to:
Java Syntax (Toggle Plain Text)
mySplash = new Splash(this, "c:\yourpic.png");
As long as the picture is actually in your c: directory and is of a png or jpeg form it should display. Tell me if this works for you. Thanks
[Edit] To illustrate my point, I have kindly attached a zip file. Which should contain the executable and the png picture. However, in order for the path to be recognised you have to EXTRACT the zipped file. Which can be done by right clicking the folder and selecting extract all... Assuming of course, you are using windows as your OS [/Edit]
*Voted best profile in the world*
Can you see what the problem is server crash? Did it work what I said. I followed instructions you gave me previously about creating a jar executable file, and the manifest crap. Is that working?
And the splash screen image I coded using javaOpengl, however, the rendering was a bit sluggish. It that took ages but I just followed the tutorials. Simple really.
Thank you for all your help
And the splash screen image I coded using javaOpengl, however, the rendering was a bit sluggish. It that took ages but I just followed the tutorials. Simple really.
Thank you for all your help
*Voted best profile in the world*
![]() |
Similar Threads
- Splash Screen (VB.NET)
- Freezes on W2K splash screen-Dell Laptop (Windows NT / 2000 / XP)
Other Threads in the Java Forum
- Previous Thread: method overloading
- Next Thread: Java Swing Calculator program not running. It has 0 errors
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image input integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loop mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working






