Solved

Picure displying

Posted on 2002-04-29
8
151 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 100 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet example 11 59
ejb on wildfly 5 47
glassfish admin console 1 22
DTD and JAVA versions 1 32
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

733 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