salut je veux savoir comment ajouter une image (background) dans JDesktopPane
j'ai ecrit le code suivant et je ne sais pas comment l'appeler
et merciii =)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 package Gui; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.LayoutManager; import java.awt.Rectangle; import java.util.Vector; import javax.swing.*; public class Contenaire extends JDesktopPane { private Image backImage = null; //member variable public Contenaire() { try { backImage = new javax.swing.ImageIcon(this.getClass().getResource("téléchargement.jpg")).getImage(); } catch(Exception e) { System.out.println("Could not find file in folder: " + this.getClass().getResource(".")); } setLayout(null); setSize(600, 600); } public void paintComponent( Graphics g ) { if(backImage == null) super.paintComponent(g); else { Graphics2D g2d = (Graphics2D)g; //scale the image to fit the size of the Panel double mw = backImage.getWidth(null); double mh = backImage.getHeight(null); double sw = getWidth() / mw; double sh = getHeight() / mh; g2d.scale(sw, sh); g2d.drawImage(backImage, 0, 0, this); } } }
Partager