Есть класс, который выводит заставку перед запуском программы:
| Код | package main.uiforms;
import main.uiforms.utils.ImgIcon;
import javax.swing.*; import java.awt.*;
public class Splash {
private JFrame splashFrame= new JFrame ();
public Splash (String imgPath, Dimension imgSize) { ImgIcon ii = new ImgIcon(); ImageIcon splashImg = ii.getImageIcon(imgPath, false); JLabel splashLabel = new JLabel (splashImg);
Rectangle screenRect = splashFrame.getGraphicsConfiguration().getBounds(); splashFrame.setSize(imgSize); splashFrame.setLocation ( screenRect.x + screenRect.width/2 - splashFrame.getSize().width/2, screenRect.y + screenRect.height/2 - splashFrame.getSize().height/2); splashFrame.setUndecorated(true);
Container splashContent = splashFrame.getContentPane(); splashContent.setBackground(Color.white);
splashContent.add(splashLabel); }
public void showSplash (long time) { splashFrame.setVisible(true); Delay (time); splashFrame.setVisible(false); }
private static void Delay (long time){
try { Thread.sleep(time); } catch (InterruptedException e) { //e.printStackTrace(); System.out.println(e.toString());
long endTime= System.currentTimeMillis() + time; while (System.currentTimeMillis() < endTime ){} } } }
|
Вызываю так:
| Код | Splash mySplash = new Splash ("resources/images/splash.gif", new Dimension(560,300)); mySplash.showSplash (2300);
|
Выводит почемуто пустой фрейм, без изображения. Пробовал по этому пути файл изображения удалять, выдает ошибку, тоесть файл видит,но не выводит. Давно уже мучаюсь, поэтому пишу. Еще наверное нужен код этого класса:
| Код | package main.uiforms.utils;
import javax.swing.ImageIcon; import java.awt.Image; import java.awt.Toolkit; import java.net.URL;
public class ImgIcon {
public ImgIcon() {}
public ImageIcon getImage (String urlname) { Image img = null;
try {
URL url = this.getClass().getResource (((urlname.substring(0)== "/")?(""):("/")) + urlname); img = Toolkit.getDefaultToolkit().getImage (url); } catch (NullPointerException npe) {
//TODO: lang variable System.err.println ("Зображення не знайдене"); }
return new ImageIcon(img); }
public Image getImage (String urlname, boolean fullPath) { Image img = null;
try { URL url = new PathUtil().getURL(urlname); //System.out.println(url); if (fullPath) { img = Toolkit.getDefaultToolkit().getImage (urlname); } else { img = Toolkit.getDefaultToolkit().getImage (url); } } catch (NullPointerException npe) { System.err.println ("Image [" + urlname + "] not found."); }
return img; }
public ImageIcon getImageIcon (String urlname, boolean fullPath) {
return new ImageIcon (getImage(urlname, fullPath)); } }
|
|