|
Ajouter une image de fond à une JPanel
|
 Voici une fenêtre avec un fond personnalisé.
Et voici le code correspondant:
import java.awt.Graphics; import java.awt.Toolkit;
import javax.swing.JFrame;
public class Fenetre extends JFrame { private String image = "image.jpg"; public Fenetre() { this.setSize(400,400); this.setLocationRelativeTo(null); this.setVisible(true); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); } @Override public void paint(Graphics arg0) { arg0.drawImage(Toolkit.getDefaultToolkit().getImage(image),0,0,null); } /** * @param args */ public static void main(String[] args) { new Fenetre(); }
}
|
|
|