allora ho una classe ImageProvider dove viene chiamato nel costruttore il readerXML e ne estrapola i dati da elaborare
la classe readerXML che legge il file XMLcodice:public ImageProvider() { width = 0; height = 0; nomeImmagine = new HashMap<>(); readerXML = new ReaderXML(); readerXML.readerXmlImage(); caricaImmagini = readerXML.getDatiCaricamentoImmagini(); for (Map.Entry<String, String> entry : caricaImmagini.entrySet()) { String nome = entry.getKey(); String path = entry.getValue(); System.out.println("nome: " + nome); System.out.println("pathPrimaMappa: " + path); try { imgURL = this.getClass().getResource("images" + File.separator + "menuImages" + File.separator + "menuPrincipale.jpg"); System.out.println("path:" + path); System.out.println("imgURL"+ imgURL); BufferedImage img = ImageIO.read(imgURL); BufferedImage momentanea = getScaledImage(img, 500, 500); nomeImmagine.put(nome, momentanea); // for (Map.Entry<String, BufferedImage> entry1 : nomeImmagine.entrySet()) { // String string = entry1.getKey(); // BufferedImage bufferedImage = entry1.getValue(); // System.out.println("nome: " + string + " bufferedImage: " + bufferedImage); // } } catch (IOException ex) { Logger.getLogger(ImageProvider.class.getName()).log(Level.SEVERE, null, ex); } } }
e questo è l'xml :codice:public void readerXmlImage() { try { DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = documentFactory.newDocumentBuilder(); Document document = builder.parse(new File("./src/it/igpe/hookBoxingGUI/Immagini.xml")); NodeList immagine = document.getElementsByTagName("Immagine"); // System.out.println("Totale persone: " + immagine.getLength()); for (int i = 0; i < immagine.getLength(); i++) { Node nodo = immagine.item(i); if (nodo.getNodeType() == Node.ELEMENT_NODE) { Element persona = (Element) nodo; String path = persona.getElementsByTagName("Path").item(0).getFirstChild().getNodeValue(); String nome = persona.getElementsByTagName("Nome").item(0).getFirstChild().getNodeValue(); this.datiCaricamentoImmagini.put(nome, path); // System.out.println("Nome: " + nome); } } } catch (Exception e) { e.printStackTrace(); } }
il percorso non è relativo in base a dove viene chiamato il path?? quindi dove è il .class dell'imageprovider o comunque nel package dove è il .java dell'imageprovider?codice:<root> <Immagine> <Path> "images/menuImages/menuPrincipale.jpg" </Path> <Nome> "menu" </Nome> </Immagine> </root>

Rispondi quotando