Splash Example Using JFrame
package com.deepsingh44.blogspot.ui;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
public class Splash extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
Splash frame = new Splash();
}
/**
* Create the frame.
*/
public Splash() {
try {
UIManager.setLookAndFeel(UIManager.
getInstalledLookAndFeels()[1].getClassName());
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
setUndecorated(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 200);
setLocationRelativeTo(null);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
JLabel lblNewLabel = new JLabel(
resize(new ImageIcon(Splash.class.
getResource("/com/deepsingh44/blogspot/images/back.jpg")),
300, 200));
contentPane.add(lblNewLabel, BorderLayout.CENTER);
JProgressBar pb = new JProgressBar();
pb.setStringPainted(true);
pb.setIndeterminate(true);
contentPane.add(pb, BorderLayout.SOUTH);
setVisible(true);
for (int i = 0; i <= 100; i++) {
pb.setValue(i);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static ImageIcon resize(ImageIcon im, int w, int h) {
BufferedImage bi = new BufferedImage(w, h,
BufferedImage.TRANSLUCENT);
Graphics2D gd = (Graphics2D) bi.createGraphics();
gd.addRenderingHints(new RenderingHints(
RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY));
gd.drawImage(im.getImage(), 0, 0, w, h, null);
gd.dispose();
return new ImageIcon(bi);
}
}
No comments:
Post a Comment