import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.io.File;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JFrame;
/*
* Created on 20.02.2004
*
* To change the template for this generated file go to Window - Preferences -
* Java - Code Generation - Code and Comments
*/
/**
* @author Administrator
*
* To change the template for this generated type comment go to Window -
* Preferences - Java - Code Generation - Code and Comments
*/
public class CoolSplash extends JFrame {
private int defaultScreenWidthMargin = 50;
private int defaultScreenHeightMargin = 37;
private Image capture;
private Image picture;
private Timer timer;
/**
* @param file
*/
public CoolSplash(File file, int w, int h, long millis) {
int newW = w + defaultScreenWidthMargin;
int newH = h + defaultScreenHeightMargin;
setSize(newH, newH);
setUndecorated(true);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int frmX = ((int) d.getWidth() - (w + defaultScreenWidthMargin)) / 2;
int frmY = ((int) d.getHeight() - (h + defaultScreenHeightMargin)) / 2;
setLocation(frmX, frmY);
try {
Robot rob = new Robot();
Rectangle rect = new Rectangle(frmX, frmY, newW, newH);
capture = rob.createScreenCapture(rect);
} catch (AWTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
MediaTracker mt = new MediaTracker(this);
try {
picture = Toolkit.getDefaultToolkit().getImage(file.toURL())
.getScaledInstance(w, h, Image.SCALE_SMOOTH);
//ImageIO.read(file).getScaledInstance(w, h,Image.SCALE_SMOOTH);
mt.addImage(picture, 0);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
mt.waitForAll();
} catch (InterruptedException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
setVisible(true);
if (picture == null)
picture = createImage(w, h);
timer = new Timer();
timer.schedule(new ExitTimerTask(this), millis);
// TODO Auto-generated constructor stub
}
public static void main(String[] args) {
new CoolSplash(new File("c:/Test.gif"), 400, 300, 5000l);
}
public void paint(Graphics g) {
if (picture != null && capture != null) {
capture.getGraphics().drawImage(picture,
0 + defaultScreenWidthMargin / 2,
0 + defaultScreenHeightMargin / 2, this);
g.drawImage(capture, 0, 0, this);
}
}
class ExitTimerTask extends TimerTask {
private JFrame frm;
public ExitTimerTask(JFrame frm) {
this.frm = frm;
}
/*
* (non-Javadoc)
*
* @see java.util.TimerTask#run()
*/
public void run() {
// TODO Auto-generated method stub
frm.setVisible(false);
frm.dispose();
System.exit(0);
}
}
}