Question
Can you modify the below simple code to achieve that when run it displays a splash screen with an image of your liking and any
Can you modify the below simple code to achieve that when run it displays a splash screen with an image of your liking and any sentence at the bottom of the splash window?
import java.awt.*; import javax.swing.*; public class SplashScreenDemo extends JWindow { /* Swing components are serializable and require serialVersionUID */ private static final long serialVersionUID = 6248477390124803341L; private final int duration; /** Default constructor. Sets the show time of the splash screen. */ public SplashScreenDemo(int duration) { this.duration = duration; } /** Shows a splash screen in the center of the desktop for the amount of time given in the constructor. */ public void showSplashWindow() { //create content pane JPanel content = new JPanel(new BorderLayout()); // or use the window content pane // JPanel content = (JPanel)getContentPane(); content.setBackground(Color.GRAY); // Set the window's bounds, position the window in the center of the screen int width = 534+10; int height = 263+10; Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); int x = (screen.width-width)/2; int y = (screen.height-height)/2; //set the location and the size of the window setBounds(x,y,width,height);
// create the splash screen JLabel label = new JLabel(new ImageIcon("SplashSwing.gif")); JLabel demo = new JLabel("SBahr's App Splash Window Demo", JLabel.CENTER); demo.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 14)); content.add(label, BorderLayout.CENTER); content.add(demo, BorderLayout.SOUTH); // create custom RGB color Color customColor = new Color(44, 197, 211); content.setBorder(BorderFactory.createLineBorder(customColor, 10)); // Container contentPane = getContentPane(); // contentPane.add(content); // add(content); //replace the window content pane with the content JPanel setContentPane(content);
// Display it // pack(); //make the splash window visible setVisible(true);
// Wait a little while doing nothing, while the application is loading try { Thread.sleep(duration); } catch (Exception e) {e.printStackTrace();} //destroy the window and release all resources dispose(); //hide the splash window, the resources will not be released //setVisible(false); }
/** The main method. Used for testing purposes. @param args the time duration of the splash screen in milliseconds. If not specified, the default duration is 10000 msec (10 sec). */ public static void main(String[] args) { int duration = 10000; if(args.length == 1){ try{ duration = Integer.parseInt(args[0]); }catch (NumberFormatException mfe){ System.out.println("Wrong command line argument: must be an integer number"); System.out.println("The default duration 10000 milliseconds will be used"); //mfe.printStackTrace(); } } // Create the screen SplashScreenDemo splashWindow = new SplashScreenDemo(duration); // Normally,the splash.showSplashWindow() will be called by the main application class. splashWindow.showSplashWindow(); }//end main }// end SplashScreenDemo class
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started