1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| import javax.swing.*;
import java.io.File;
import javax.imageio.*;
import java.io.File.*;
import java.lang.NullPointerException;
import java.io.*;
import java.awt.*;
class TigerContents extends JPanel
{
public BufferedImage monImage;
public TigerContents(String url)
{
super();
try
{
this.monImage = ImageIO.read(new File(url));
}
catch(java.io.IOException e)
{
}
try
{
System.out.println( ((BufferedImage)monImage).getHeight() );
this.setPreferredSize(new Dimension(434, 320)); // Dimension que tu veux
}
catch(java.lang.NullPointerException e2)
{
}
}
public void paintComponent(Graphics g)
{
super.paintComponent(g); // repeint le fond du JPanel
g.drawImage(monImage,0,0,getWidth(),getHeight(),this);
}
}
class Menu_General extends JFrame
{
public Menu_General(String url)
{
super();
setTitle("Menu General");
TigerContents panel;
// url = chemin de l'image que tu veux afficher. Lors de l'appel de TigerFrame ne pas oublier de préciser le chemin de l'image
panel = new TigerContents(url);
this.setContentPane(panel);
pack(); // ajuster la taille de la fenètre
show(); // affiche la fenetre
this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}
public static void main(String[] args)
{
Menu_General m= new Menu_General("C:\\4.PNG");
m.setBounds(240,120,420,470);
}
} |