944,137 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3310
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Feb 11th, 2006
0

splash screen woes

Expand Post »
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:

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);
    }
  }
Attached Files
File Type: zip thwee.zip (104.1 KB, 28 views)
Similar Threads
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Feb 12th, 2006
0

Re: splash screen woes

Don't tell me you are creating a pause with System.out.println() ? Use threads and make it sleep.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Feb 12th, 2006
0

Re: splash screen woes

Quote originally posted by server_crash ...
Don't tell me you are creating a pause with System.out.println() ? Use threads and make it sleep.
Can you show me an example using a thread? I don't see how that would make a difference? Explain?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Feb 12th, 2006
0

Re: splash screen woes

It'll make a huge difference.
Java Syntax (Toggle Plain Text)
  1. class Test implements Runnable
  2. {
  3. public Test()
  4. {
  5. super();
  6.  
  7. Thread t = new Thread(this);
  8. t.start();
  9. //t.run(); can't remember if you have to call this or not
  10. }
  11.  
  12. public void run()
  13. {
  14. while (true)
  15. {
  16. try
  17. {
  18. System.out.println("In Run");
  19. Thread.sleep(2000);
  20. }
  21. catch(InterruptedException ie)
  22. {
  23. }
  24. }
  25. }
  26. }

It's not tested, but if you simply want a delay then use threads.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Feb 12th, 2006
0

Re: splash screen woes

Quote originally posted by server_crash ...
It'll make a huge difference.
Java Syntax (Toggle Plain Text)
  1. class Test implements Runnable
  2. {
  3. public Test()
  4. {
  5. super();
  6.  
  7. Thread t = new Thread(this);
  8. t.start();
  9. //t.run(); can't remember if you have to call this or not
  10. }
  11.  
  12. public void run()
  13. {
  14. while (true)
  15. {
  16. try
  17. {
  18. System.out.println("In Run");
  19. Thread.sleep(2000);
  20. }
  21. catch(InterruptedException ie)
  22. {
  23. }
  24. }
  25. }
  26. }

It's not tested, but if you simply want a delay then use threads.
Thanks for your help but I still don't see how mine won't work.

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)
  1. //Splash.java
  2. import java.awt.*;
  3. import java.awt.event.*;
  4.  
  5. public class Splash extends Window {
  6. private Image splashImage;
  7. private int imgWidth, imgHeight;
  8. private String imgName;
  9. private static final int BORDERSIZE = 0;
  10. private static final Color BORDERCOLOR = Color.WHITE;
  11. Toolkit tk;
  12.  
  13. public Splash(Frame f, String imgName) {
  14. super(f);
  15. this.imgName = imgName;
  16. tk = Toolkit.getDefaultToolkit();
  17. splashImage = loadSplashImage();
  18. showSplashScreen();
  19. f.addWindowListener(new WindowListener());
  20. }
  21. public Image loadSplashImage() {
  22. MediaTracker tracker = new MediaTracker(this);
  23. Image result;
  24. result = tk.getImage(imgName);
  25. tracker.addImage(result, 0);
  26. try {
  27. tracker.waitForAll();
  28. }
  29. catch (Exception e) {
  30. e.printStackTrace();
  31. }
  32. imgWidth = result.getWidth(this);
  33. imgHeight = result.getHeight(this);
  34. return (result);
  35. }
  36.  
  37. public void showSplashScreen() {
  38. Dimension screenSize = tk.getScreenSize();
  39. setBackground(BORDERCOLOR);
  40. int w = imgWidth + (BORDERSIZE * 2);
  41. int h = imgHeight + (BORDERSIZE * 2);
  42. int x = (screenSize.width - w) /2;
  43. int y = (screenSize.height - h) /2;
  44. setBounds(x, y, w, h);
  45. setVisible(true);
  46. }
  47.  
  48. public void paint(Graphics g) {
  49. g.drawImage(splashImage, BORDERSIZE, BORDERSIZE,
  50. imgWidth, imgHeight, this);
  51. }
  52.  
  53. class WindowListener extends WindowAdapter {
  54. // was windowActivated, thanks to H.Grippa for the fix!
  55. public void windowOpened(WindowEvent we) {
  56. setVisible(false);
  57. dispose();
  58. }
  59. }
  60. }

Java Syntax (Toggle Plain Text)
  1. //TestSplash.java
  2. import java.awt.*;
  3. import java.awt.event.*;
  4.  
  5. public class TestSplash {
  6. MyFrame theFrame;
  7.  
  8.  
  9. public static void main (String args[]){
  10. TestSplash t = new TestSplash();
  11. t.createMainFrame();
  12. }
  13.  
  14. private void createMainFrame() {
  15. theFrame = new MyFrame("A Dummy Frame");
  16. theFrame.setVisible(true);
  17. }
  18.  
  19. }
  20.  
  21. class MyFrame extends Frame {
  22. Splash mySplash;
  23. public MyFrame(String title){
  24. super(title);
  25. addWindowListener
  26. (new WindowAdapter() {
  27. public void windowClosing(WindowEvent e) {
  28. System.exit(0);
  29. }
  30. }
  31. );
  32. //file needs to be jpeg or png
  33. mySplash = new Splash(this, "blart.png");
  34. Thread.sleep(2000);
  35. // dummy delay so we can see the Splash!
  36. //for(int i = 0; i < 50000; i++) {
  37. //System.out.println(i) ;
  38. //}
  39. setSize(200,200);
  40. }
  41. }
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Feb 12th, 2006
0

Re: splash screen woes

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.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Feb 12th, 2006
0

Re: splash screen woes

Quote 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.
You haven't tried it have you? There is an executable in my attachment which should emphasise my point. LOL.

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...
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Feb 12th, 2006
0

Re: splash screen woes

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?
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Feb 12th, 2006
0

Re: splash screen woes

Quote 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?
You need to make sure the path to your splash screen image is actually there.

For example

Java Syntax (Toggle Plain Text)
  1. mySplash = new Splash(this, "blart.png");

would be changed to:

Java Syntax (Toggle Plain Text)
  1. 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]
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Feb 12th, 2006
0

Re: splash screen woes

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
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: using MouseMotionListener() with a .gif image
Next Thread in Java Forum Timeline: Java Swing Calculator program not running. It has 0 errors





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC