Solved

Picure displying

Posted on 2002-04-29
8
148 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
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTTPSessionBindingListernter not configured in deployment descriptor 2 65
hibernate example using maven 12 56
Java string replace 11 53
Is there a simpler dropbox system? 10 34
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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…
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 will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

791 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