[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Picure displying

Posted on 2002-04-29
8
Medium Priority
?
157 Views
Last Modified: 2010-03-31
I got a Java program which uses a desktop pane and a logo picture (JPEG about 300*500px size). When the program is  run, firstly, I want the logo picture to be displayed on top of the desktop frame (ideally in the centre of the desktop pane) for about 3 seconds. After 3 seconds I want it to be disappeared.  I will appreciate if anyone could tell me the easiest way to do this.
Thanx
0
Comment
Question by:asukai
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 6977871
you could use something like this:

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
/*
<APPLET
        code=NagScreen.class
        width=600
        height=450>
</applet>
*/

public class NagScreen extends java.applet.Applet implements Runnable, ImageObserver {
   
     private Image curImage;
     private Thread t;
     
     public void init()
     {
          curImage = getImage(getCodeBase(), "pic1.jpg");
          t = new Thread(this);    
          t.setPriority(Thread.NORM_PRIORITY);
          t.start();
     }
     
     public void paint(Graphics g) {
          if (curImage != null) g.drawImage(curImage, 0, 0, this);
        }


     // this is the routine that will query your asp page and disp results
     public void run() {
         
          try {
               // sleep for 3 seconds
               t.sleep(3000);          
               curImage = null;
               repaint();
                } catch (Exception e) {
               curImage = null;
          }
     }          
}
0
 

Author Comment

by:asukai
ID: 6978409
Dear bobbit31
Thanx for your comment. However the code seems not to work on mine. It displays the image but menu bars start not working correctly and the window keeps flicking... Also the program is not an applet.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6978485
can you post your code?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 92

Expert Comment

by:objects
ID: 6978881
> Also the program is not an applet.

What do you think it is??

Add the following method to fix the flickering:

public void update(Graphics g)
{
   paint(g);
}
0
 
LVL 9

Expert Comment

by:Ovi
ID: 6979598
Is AWT or SWING application ?
0
 

Author Comment

by:asukai
ID: 6979758
It's a SWING application
0
 
LVL 9

Accepted Solution

by:
Ovi earned 400 total points
ID: 6979815
The technique for splash screens usually use JWindows.

So you need to do something like this :

public class Test {
  public Test() {
    ....
    showSplash();
    ....
  }
............

  public void showSplash() {
    new Thread(new Runnable() {
      public void run() {
        JWindow splash = new JWindow();        
        // centering the splash
        splash.setSize(500, 400);
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
       
        splash.setLocation((screen.width - splash.getSize().width)/2, (screen.height - splash.getSize().height)/2);
       // should be centered relative to screen

        splash.setLayout(new BorderLayout());
        ImageIcon splashImg = new ImageIcon(Test.this.getClass().getResource("path to your JPG goes here"));
        JLabel label = new JLabel(splashImg);
        label.setText("");
        splash.add(label, BorderLayout.CENTER);
        splash.setVisible(true);
        try { Thread.sleep(5000); } catch(Exception e) {}
        splash.setVisible(false);
        splash.dispose();
      }
    }).start();
  }
............
}
0
 
LVL 9

Expert Comment

by:Ovi
ID: 6979820
You should replace in my code as appropiate to your source (e.g. "Test.this" with your class instance; dummy path in getResource method with a real path to your image).
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question