SplashWindow1.java
package jiang.splash;
import javax.swing.*;
import java.awt.*;
/**
*
Description:
Copyright: Copyright (c) 2005
Company:
public static void main(String[] args) {
String fn = "images/mysplash.jpg";
Frame fm = new Frame();
SplashWindow1 Login = new SplashWindow1(fn, fm);
}
}
SplashWindow2.java
package jiang.splash;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
*
*
Description:
Copyright: Copyright (c) 2005
Company:
class SplashWindow2 extends JWindow
{
public SplashWindow2(String filename, Frame f)
{
super(f);
JLabel l = new JLabel(new ImageIcon(filename));
getContentPane().add(l, BorderLayout.CENTER);
pack();
Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
Dimension labelSize = l.getPreferredSize();
setLocation(screenSize.width/2 - (labelSize.width/2),
screenSize.height/2 - (labelSize.height/2));
addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
setVisible(false);
dispose();
}
});
setVisible(true);
}
public static void main(String[] args) {
String fn = "images/mysplash.jpg";
Frame fm = new Frame();
SplashWindow2 Login = new SplashWindow2(fn, fm);
}
}
SplashWindow3.java
package jiang.splash;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
*
*
Description:
Copyright: Copyright (c) 2005
Company:
class SplashWindow3 extends JWindow
{
public SplashWindow3(String filename, Frame f, int waitTime)
{
super(f);
JLabel l = new JLabel(new ImageIcon(filename));
getContentPane().add(l, BorderLayout.CENTER);
pack();
Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
Dimension labelSize = l.getPreferredSize();
setLocation(screenSize.width/2 - (labelSize.width/2),
screenSize.height/2 - (labelSize.height/2));
addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
setVisible(false);
dispose();
}
});
final int pause = waitTime;
final Runnable closerRunner = new Runnable()
{
public void run()
{
setVisible(false);
dispose();
}
};
Runnable waitRunner = new Runnable()
{
public void run()
{
try
{
Thread.sleep(pause);
SwingUtilities.invokeAndWait(closerRunner);
}
catch(Exception e)
{
e.printStackTrace();
// 能够捕获InvocationTargetException
// 能够捕获InterruptedException
}
}
};
setVisible(true);
Thread splashThread = new Thread(waitRunner, "SplashThread");
splashThread.start();
}
public static void main(String[] args) {
String fn = "images/mysplash.jpg";
Frame fm = new Frame();
SplashWindow3 Login = new SplashWindow3(fn, fm, 2000);
}
}
SplashWindow4.java
package jiang.splash;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.*;
/**
*
*
Description:
Copyright: Copyright (c) 2005
Company:
public class SplashWindow4 extends JWindow {
public SplashWindow4(String imgPath, Frame f, int waitTime) {
super(f);
JLabel lMain = new JLabel(new ImageIcon(imgPath + "logo_main3.jpg"));
JLabel lEast = new JLabel(new ImageIcon(imgPath + "logo_east.jpg"));
JLabel lSouth = new JLabel(new ImageIcon(imgPath + "logo_south.jpg"));
JLabel lWest = new JLabel(new ImageIcon(imgPath + "logo_west.jpg"));
final JProgressBar p = new JProgressBar();
getContentPane().add(lMain, BorderLayout.NORTH);
getContentPane().add(lSouth, BorderLayout.SOUTH);
getContentPane().add(lEast, BorderLayout.EAST);
getContentPane().add(lWest, BorderLayout.WEST);
getContentPane().add(p, BorderLayout.CENTER);
p.setBorderPainted(false);
p.setBorder(null);
p.setPreferredSize(new Dimension(p.getSize().width, 6));
p.setForeground(new Color(153,153,204));
pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension splashSize = new Dimension(lMain.getPreferredSize().width,
lMain.getPreferredSize().height +
p.getPreferredSize().height +
lSouth.getPreferredSize().height);
setLocation(screenSize.width / 2 - (splashSize.width / 2),
screenSize.height / 2 - (splashSize.height / 2));
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
setVisible(false);
dispose();
}
});
final int pause = waitTime;
final Runnable closerRunner = new Runnable() {
public void run() {
setVisible(false);
dispose();
}
};
Runnable waitRunner = new Runnable() {
public void run() {
try {
Thread.sleep(pause);
SwingUtilities.invokeAndWait(closerRunner);
} catch (Exception e) {
e.printStackTrace();
// 能够捕获InvocationTargetException
// 能够捕获InterruptedException
}
}
};
Runnable progress = new Runnable() {
public void run() {
for (int i = 1; i <= 50; i++) {
p.setValue(i * 2);
try {
Thread.sleep(pause / 50);
} catch (InterruptedException ex) {
}
}
}
};
setVisible(true);
Thread splashThread = new Thread(waitRunner, "SplashThread");
splashThread.start();
Thread progressThread = new Thread(progress, "ProgressThread");
progressThread.start();
}
public static void main(String[] args) {
String imgPath = "images/";
Frame fm = new Frame();
SplashWindow4 Login = new SplashWindow4(imgPath, fm, 10000);
}
}