Bonjour, je souhaite que mon JPanel affiche une capture dynamique de ce qui ce trouve derrière lui, en gros imiter la transparence!
Le problème c'est que je n'arrive à afficher que le coin en haut à gauche de mon écran et je ne comprend pas trop pourquoi, si une âme secourable pouvais m'aider
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 import java.awt.AWTException; import java.awt.Graphics; import java.awt.Rectangle; import java.awt.Robot; import java.awt.image.BufferedImage; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.WindowConstants; public class FrameTransparente extends JFrame public FrameTransparente() { pack(); setSize(400, 400); setLocationRelativeTo(null); setContentPane(new panCapture()); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); } public static void main(String[] args) { new FrameTransparente().setVisible(true); } class panCapture extends JPanel { public panCapture() { } @Override public void paintComponent(Graphics g) { try { Robot robot = new Robot(); BufferedImage image = robot.createScreenCapture(new Rectangle(this.getX(), this.getY(), this.getWidth(), this.getHeight())); g.drawImage(image, this.getX(), this.getY(), this); repaint(); } catch (AWTException ex) { System.out.println(ex); } } } }
Partager