This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

spalsh screen  RSS feed

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi frenz ... i want to make a splash Screen that get disposed after main program screen shows up... but i m not sure of the time that will be taken by the main program... secondly if there is any problem in the main program than it should be intimated to the user...plz help

Sandeep Kumar
 
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can study (or use outright) any number of splashscreen classes. Some of them come with explanations on how to do and not to do splash screens.
 
Ranch Hand
Posts: 824
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this code



import javax.swing.*;
import java.awt.*;

public class SplashScreen extends JWindow {
BorderLayout borderLayout1 = new BorderLayout();
JLabel imageLabel = new JLabel();
JPanel southPanel = new JPanel();
FlowLayout southPanelFlowLayout = new FlowLayout();
JProgressBar progressBar = new JProgressBar();
ImageIcon imageIcon;

public SplashScreen(ImageIcon imageIcon) {
this.imageIcon = imageIcon;
try {
jbInit();
}
catch(Exception ex) {
ex.printStackTrace();
}
}

// note - this class created with JBuilder
void jbInit() throws Exception {
imageLabel.setIcon(imageIcon);
this.getContentPane().setLayout(borderLayout1);
southPanel.setLayout(southPanelFlowLayout);
southPanel.setBackground(Color.pink);
((JPanel)getContentPane()).setBorder(BorderFactory.createRaisedBevelBorder());
this.getContentPane().add(imageLabel, BorderLayout.CENTER);
this.getContentPane().add(southPanel, BorderLayout.SOUTH);
southPanel.add(progressBar, null);
this.pack();
}

public void setProgressMax(int maxProgress)
{
progressBar.setMaximum(maxProgress);
}

public void setProgress(int progress)
{
final int theProgress = progress;
SwingUtilities.invokeLater(new Runnable() {
public void run() {
progressBar.setValue(theProgress);
}
});
}

public void setProgress(String message, int progress)
{
final int theProgress = progress;
final String theMessage = message;
setProgress(progress);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
progressBar.setValue(theProgress);
setMessage(theMessage);
}
});
}

public void setScreenVisible(boolean b)
{
final boolean boo = b;
SwingUtilities.invokeLater(new Runnable() {
public void run() {
setVisible(boo);
}
});
}

private void setMessage(String message)
{
if (message==null)
{
message = "";
progressBar.setStringPainted(false);
}
else
{
progressBar.setStringPainted(true);
}
progressBar.setString(message);
}

}////////////////////////////End//////////////////////////////////



import javax.swing.UIManager;
import javax.swing.ImageIcon;

public class SplashScreenMain {

SplashScreen screen;

public SplashScreenMain() {
// initialize the splash screen
splashScreenInit();
// do something here to simulate the program doing something that
// is time consuming
for (int i = 0; i <= 100; i++)
{
for (long j=0; j<50000; ++j)
{
String poop = " " + (j + i);
}
// run either of these two -- not both
screen.setProgress("Yo " + i, i); // progress bar with a message
//screen.setProgress(i); // progress bar with no message
}
splashScreenDestruct();
System.exit(0);
}

private void splashScreenDestruct() {
screen.setScreenVisible(false);
}

private void splashScreenInit() {
ImageIcon myImage = new ImageIcon("C:/sunil/sunil/myself/enter.gif");
screen = new SplashScreen(myImage);
screen.setLocationRelativeTo(null);
screen.setProgressMax(100);
screen.setScreenVisible(true);
}

public static void main(String[] args)
{
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {
e.printStackTrace();
}
new SplashScreenMain();
}

}//////////////////////////////End ///////////////////////////////////



Enjoy
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!