Salut a tous !
Je voudrais mettre une image en fond d'une JFrame. J'ai regardé dans la FAQ et j'ai trouvé cela :
Et voici mon code qui appelle la JFrame dans laquelle je voudrais mettre une image :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 public class MonPanel extends JComponent { /* variable de classe contennant l'image à afficher en fond */ private Image bg; /* Surcharge de la fonction paintComponent() pour afficher notre image */ public void paintComponent(Graphics g) { g.drawImage(bg,0,0,null); } }
Je suis débutant en Java et donc je voudrais savoir comment inclure le premier code (celui de la FAQ) dans mon code.
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
50
51
52
53 import java.awt.*; import java.awt.event.*; public class eh_Nak implements WindowListener { public static void main (String[] args) { theApp = new eh_Nak(); theApp.init(); } public void init() { window = new EsquisseFrame("titre"); Toolkit leKit = window.getToolkit(); Dimension wndSize = leKit.getScreenSize(); window.setBounds((wndSize.width/wndSize.width)-1, (wndSize.height/wndSize.height)-1, wndSize.width, wndSize.height); window.addWindowListener(this); window.setVisible(true); } public void windowClosing(WindowEvent e) { window.dispose(); System.exit(0); } public void windowOpened(WindowEvent e){} public void windowClosed(WindowEvent e){} public void windowIconified(WindowEvent e){} public void windowDeiconified(WindowEvent e){} public void windowActivated(WindowEvent e){} public void windowDeactivated(WindowEvent e){} private static EsquisseFrame window; private static eh_Nak theApp; }
Merci d'avance
Partager