Solved

Picure displying

Posted on 2002-04-29
8
142 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mockito example issue 8 64
JUnit 4 @Before and @BeforeClass differences 3 49
session migration servlets 2 28
table example 4 25
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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 will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

863 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

18 Experts available now in Live!

Get 1:1 Help Now