Vydělávej až 160.000 Kč měsíčně! Akreditované rekvalifikační kurzy s garancí práce od 0 Kč. Více informací.
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.

Diskuze: Načítání obrázků

Aktivity
Avatar
T.vp
Člen
Avatar
T.vp:3.8.2014 14:29

Ahoj IT kamarádi :)

Řeším jeden problém s načítáním obrázku v javě. Mám vytvořenou aplikaci, která v NetBeans funguje jak má, ale když z ní vytvořím pomocí clean and build jar soubor, tak odmítá načíst obrázky. Main třída je uložená v balíčku circuit.simulator a třída pro načítání je včetně obrázků v balíčku circuit.simula­tor.pictures Třída se jmenuje LoadImages a přikládám její kód. Mimo to mi na výstupu vyskočí tato hláška

....\src\circu­it\simulator\Cir­cuitSimulator­.java:14: warning: DependencyClass is internal proprietary API and may be removed in a future release
import java.awt.Cursor;
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 warning

Vážně už nevím kde mám chybu, budu vděčný za jakoukoliv radu.

public class LoadImages {

static private BufferedImage blueBkg;
static private BufferedImage greenBkg;
static private BufferedImage newGame;
static private BufferedImage saveGame;
static private BufferedImage loadGame;
static private BufferedImage pause;
static private BufferedImage stop;
static private BufferedImage play;
static private BufferedImage ac;
static private BufferedImage dc;
static private BufferedImage vector;

public LoadImages() throws IOException {

URL urlBlueBkg = (this.getClas­s()).getResou­rce("blue.png");
URL urlGreenBkg = (this.getClas­s()).getResou­rce("green.png");
URL newG = (this.getClas­s()).getResou­rce("newGame.png");
URL saveG = (this.getClas­s()).getResou­rce("save.png");
URL loadG = (this.getClas­s()).getResou­rce("load.png");
URL pausC = (this.getClas­s()).getResou­rce("myPause.png");
URL stopC = (this.getClas­s()).getResou­rce("stop.png");
URL playC = (this.getClas­s()).getResou­rce("myPlay.png");
URL aC = (this.getClas­s()).getResou­rce("ac.png");
URL dC = (this.getClas­s()).getResou­rce("dc.png");
URL vectoR = (this.getClas­s()).getResou­rce("vector.png");

try {
LoadImages.blueBkg = ImageIO.read(ur­lBlueBkg);
LoadImages.greenBkg = ImageIO.read(ur­lGreenBkg);
LoadImages.newGame = ImageIO.read(newG);
LoadImages.saveGame = ImageIO.read(sa­veG);
LoadImages.loadGame = ImageIO.read(lo­adG);
LoadImages.pause = ImageIO.read(pau­sC);
LoadImages.play = ImageIO.read(pla­yC);
LoadImages.stop = ImageIO.read(stop­C);
LoadImages.ac = ImageIO.read(aC);
LoadImages.dc = ImageIO.read(dC);
LoadImages.vector = ImageIO.read(vec­toR);

} catch (IOException e) {
JOptionPane.show­MessageDialog(new JFrame(), "Přidané soubory s obrázky nebyly nalezeny!");
System.exit(0);
}
}
}

 
Odpovědět
3.8.2014 14:29
Avatar
mara
Člen
Avatar
Odpovídá na T.vp
mara:4.8.2014 21:17

vlož to sem takto

použij tlačítko vložit zdrojový kód... zůstane formátování a líp se v tom hledá...
Nahoru Odpovědět
4.8.2014 21:17
Co na srdci, to na Facebooku
Avatar
T.vp
Člen
Avatar
T.vp:10.8.2014 10:28

Problém jsem vyřešil, šlo o chybu v názvu obrázku, NetBeans zřejmě neřeší malá a velká písmena v názvu souboru. Ve výsledném jar souboru už to ale problém byl. Třeba bude někdy někdo řešit podobný problém a pomůže mu to :)

 
Nahoru Odpovědět
10.8.2014 10:28
Avatar
T.vp
Člen
Avatar
T.vp:10.8.2014 10:29
public class LoadImages {

static private BufferedImage blueBkg;
static private BufferedImage greenBkg;
static private BufferedImage newGame;
static private BufferedImage saveGame;
static private BufferedImage loadGame;
static private BufferedImage pause;
static private BufferedImage stop;
static private BufferedImage play;
static private BufferedImage ac;
static private BufferedImage dc;
static private BufferedImage vector;

public LoadImages() throws IOException {

URL urlBlueBkg = (this.getClass()).getResource("blue.png");
URL urlGreenBkg = (this.getClass()).getResource("green.png");
URL newG = (this.getClass()).getResource("newGame.png");
URL saveG = (this.getClass()).getResource("save.png");
URL loadG = (this.getClass()).getResource("load.png");
URL pausC = (this.getClass()).getResource("myPause.png");
URL stopC = (this.getClass()).getResource("stop.png");
URL playC = (this.getClass()).getResource("myPlay.png");
URL aC = (this.getClass()).getResource("ac.png");
URL dC = (this.getClass()).getResource("dc.png");
URL vectoR = (this.getClass()).getResource("vector.png");

try {
LoadImages.blueBkg = ImageIO.read(urlBlueBkg);
LoadImages.greenBkg = ImageIO.read(urlGreenBkg);
LoadImages.newGame = ImageIO.read(newG);
LoadImages.saveGame = ImageIO.read(saveG);
LoadImages.loadGame = ImageIO.read(loadG);
LoadImages.pause = ImageIO.read(pausC);
LoadImages.play = ImageIO.read(playC);
LoadImages.stop = ImageIO.read(stopC);
LoadImages.ac = ImageIO.read(aC);
LoadImages.dc = ImageIO.read(dC);
LoadImages.vector = ImageIO.read(vectoR);

} catch (IOException e) {
JOptionPane.showMessageDialog(new JFrame(), "Přidané soubory s obrázky nebyly nalezeny!");
System.exit(0);
}
}
}
 
Nahoru Odpovědět
10.8.2014 10:29
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.

Zobrazeno 4 zpráv z 4.