import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
public class TransWindow extends JFrame implements WindowListener {
private BufferedImage screen = null;
private BufferedImage background = null;
private Robot rob = null;
private Point loc = null;
public TransWindow() {
try {
rob = new Robot();
}
catch (AWTException e) {
e.printStackTrace();
System.exit(0);
}
}
private void actBackground() {
Dimension size = getSize();
background = screen.getSubimage((int)loc.getX(), (int)loc.getY(), (int)size.getWidth(), (int)size.getHeight());
repaint();
}
private void makeScreenshot() {
screen = rob.createScreenCapture(new Rectangle(getToolkit().getScreenSize()));
}
public void actTransparent() {
loc = getLocationOnScreen();
setLocation((int)getToolkit().getScreenSize().getWidth(), (int)getToolkit().getScreenSize().getHeight());
makeScreenshot();
actBackground();
setLocation(loc);
}
public void paint(Graphics g) {
super.paint(g);
g.drawImage(background, 0, 0, null);
}
public void windowActivated(WindowEvent evt) {
actTransparent();
}
public void windowDeiconified(WindowEvent evt) {
actTransparent();
}
public void windowOpened(WindowEvent evt) {
actTransparent();
}
public void windowDeactivated(WindowEvent evt) {
}
public void windowIconified(WindowEvent evt) {
}
public void windowClosed(WindowEvent evt) {
}
public void windowClosing(WindowEvent evt) {
}
}