import javax.swing.*;
import java.awt.*;
import java.net.*;public class JSplashWindow extends JWindow implements Runnable {
Thread splashThread=null;
public JSplashWindow() {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
JPanel splash = new JPanel(new BorderLayout());
URL url = getClass().getResource("");//我用的工具是Ecsplice,我想在这里显示图片,可是不知道怎样能够显示出来,怎样添加图片的路径. if(url != null){
splash.add(new JLabel(new ImageIcon(url)),
BorderLayout.CENTER);
} setContentPane(splash); Dimension screen = getToolkit().getScreenSize();
pack();
setLocation((screen.width - getSize().width) / 2,
(screen.height - getSize().height) / 2);
}public void start(){
this.toFront();
splashThread=new Thread(this);
splashThread.start();}public void run(){
try {
show();
Thread.sleep(5000);
}
catch (Exception ex) {
ex.printStackTrace();//这个也是不明白说什么,英语不好.
}
this.dispose();//这句话查jdk了,但还是不明白什么意思.
}static void showFrame(String title){
JFrame frame = new JFrame(title);
frame.setSize(400,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); frame.setVisible(true);}public static void main(String[] args) {
showFrame("Demo splash window");
JSplashWindow splash = new JSplashWindow();
splash.start();
}
}
希望祥解
import java.awt.*;
import java.net.*;public class JSplashWindow extends JWindow implements Runnable {
Thread splashThread=null;
public JSplashWindow() {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
JPanel splash = new JPanel(new BorderLayout());
URL url = getClass().getResource("/f.jpg");// PS: 此为在当前路径下放置 f.jpg 图片, if(url != null){
splash.add(new JLabel(new ImageIcon(url)),
BorderLayout.CENTER);
} setContentPane(splash); Dimension screen = getToolkit().getScreenSize();
pack();
setLocation((screen.width - getSize().width) / 2,
(screen.height - getSize().height) / 2);
}public void start(){
this.toFront();
splashThread=new Thread(this);
splashThread.start();}public void run(){
try {
show();
Thread.sleep(5000);
}
catch (Exception ex) {
ex.printStackTrace();// 打印出异常的详细信息
}
this.dispose();//释放资源
}static void showFrame(String title){
JFrame frame = new JFrame(title);
frame.setSize(400,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); frame.setVisible(true);}public static void main(String[] args) {
showFrame("Demo splash window");
JSplashWindow splash = new JSplashWindow();
splash.start();
}
}