Solved

Picure displying

Posted on 2002-04-29
8
141 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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 18

Expert Comment

by:bobbit31
Comment Utility
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
Comment Utility
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
Comment Utility
can you post your code?
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
> 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 9

Expert Comment

by:Ovi
Comment Utility
Is AWT or SWING application ?
0
 

Author Comment

by:asukai
Comment Utility
It's a SWING application
0
 
LVL 9

Accepted Solution

by:
Ovi earned 100 total points
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now