problème affichage image dans package

problème affichage image dans package - Java - Programmation

Marsh Posté le 09-03-2013 à 19:27:23    

Bonsoir tout monde,
Je vient poster une demande d'aide pour un petit problème mais qui  me fait perde beaucoup de temps après un long temps de recherche avec mon niveau très bas en programmation java j'ai décider de venir vous demander de l'aide voilà mon problème.
 
Voilà mon code:
 
package fr.horyzon;
 
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
 
public class affichage extends JFrame {
 private BufferedImage image;
 public affichage() {
  JButton btn = new JButton("Okay" );
  try {
   image = ImageIO.read(new File("C:/Users/anonyme/Documents/prototype.jpg" ));
   // Set your Image Here.
   this.setContentPane(new JLabel(new ImageIcon(image)));
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
   
 
 
  //Adding components to Panel and JFrame
 
  // JFrame Properties
  this.setSize(image.getWidth(),image.getHeight());
  this.setLayout(new FlowLayout());
  this.setResizable(true);
  this.setLocationRelativeTo(null);
  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  this.setTitle("JFrame Tutorial Update" );
  this.setVisible(true);
 
 }
 
 public static void main(String[] args) {
  new affichage();
 }
 
}
 
Je voudrait que au lieu d'aller chercher l'image sur l'ordinateur à cette lignes:
image = ImageIO.read(new File("C:/Users/anonyme/Documents/prototype.jpg" ));
Qu'il prenne l'image situer dans le même package que ma classe.
L'image se nomme prototype.png
Merci d'avance pour votre aide

Reply

Marsh Posté le 09-03-2013 à 19:27:23   

Reply

Marsh Posté le 10-03-2013 à 01:29:14    

Problème résolue par moi même, désoler du dérangement pour un problème aussi bête.

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed