Tom's Guide > Forum > Programmation > application java
Mot :    Pseudo :           
 

comment inserer une image dans une application java (jbuilder)? :-P

Liens sponsorisés
Inscrivez-vous ou connectez-vous pour masquer ceci.

Essayes ca :

Code :
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. public class ChargerImage
  5.   {
  6.   public static void main(String[] args)
  7.     {
  8.     Fenetre fenetre = new Fenetre();
  9.     fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  10.     fenetre.show();
  11.     }
  12.   }
  13. class Fenetre extends JFrame
  14.   {
  15.   public Fenetre()
  16.     {
  17.     Container leContenant = getContentPane();
  18.     leContenant.setLayout(new FlowLayout());
  19.     AffichageImage image = new AffichageImage("nom_de_ton_image.jpg" );
  20.     leContenant.add(image);
  21.     }
  22.   }
  23. class AffichageImage extends Canvas
  24.   {
  25.   Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  26.   int largeurEcran = screenSize.width;
  27.   int hauteurEcran = screenSize.height;
  28.   Image image;
  29.   public AffichageImage(String url)
  30.     {
  31.     image = getToolkit().getImage(url);
  32.     prepareImage(image, this);
  33.     }
  34.   public void paint(Graphics g)
  35.     {
  36.     g.drawImage(image, 0, 0, this);
  37.     }
  38.   public boolean imageUpdate(Image image, int info, int x, int y, int l, int h)
  39.     {
  40.     if ((info & (WIDTH | HEIGHT)) != 0)
  41.       {
  42.       setSize(l, h);
  43.       getParent().getParent().getParent().getParent().setBounds( (largeurEcran - l) / 2, (hauteurEcran - h) / 2, l+8, h+32 );
  44.       }
  45.     if ((info & (ALLBITS)) != 0)
  46.       {
  47.       repaint();
  48.       return false;
  49.       }
  50.     else
  51.       {
  52.       return true;
  53.       }
  54.     }
  55.   }



:-D

Répondre à poolos
Tom's Guide > Forum > Programmation > application java
Aller à :

Il y a 611 utilisateurs connus et inconnus. Pour voir la liste des connectés connus, cliquez ici.

Attention

Vous allez répondre sur un sujet resté inactif pendant plus de 6 mois.
Assurez-vous d'apporter des éléments nouveaux à la discussion avant de poursuivre.

Répondre Annuler
Liens