import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
@SuppressWarnings("serial")
public class Virtual_Transparency extends JFrame implements Runnable
{
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
Thread thread;
Robot r;
BufferedImage back = null;
JTextArea area;
int old_x = d.width/4;
int old_y = d.height/4;
public Virtual_Transparency()
{
super("Virtuelle Transparenz von JFrames");
setSize(d.width/2,d.height/2);
setLocation(d.width/4,d.height/4);
setLayout(new BorderLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
try
{
r = new Robot();
}
catch(Exception e)
{
}
snapFirstScreen();
addComponents();
thread = new Thread(this);
thread.start();
setVisible(true);
}
public void addComponents()
{
area = new JTextArea()
{
@Override
public void paintComponent(Graphics g)
{
g.drawImage(back,0,0,this);
area.paint(g);
}
};
area.setOpaque(false);
add(area,"Center");
}
public void snapFirstScreen()
{
setLocation(-getSize().width,-getSize().height);
back = snapScreen();
setLocation(old_x,old_y);
}
public void run()
{
while(true)
{
if(windowPositionChanged()!=false)
{
old_x = getLocation().x;
old_y = getLocation().y;
setLocation(-getSize().width,-getSize().height);
back = snapScreen();
setLocation(old_x,old_y);
repaint();
}
waitTime(1000);
}
}
public boolean windowPositionChanged()
{
boolean changed = false;
if(this.getLocation().x==old_x&&this.getLocation().y==old_y)
changed = false;
else
changed = true;
return changed;
}
public BufferedImage snapScreen()
{
BufferedImage screenShot = r.createScreenCapture
(new Rectangle(old_x,old_y,getSize().width,getSize().height));
if(screenShot==null)
{
System.err.println("Fehler beim schießen des Screenshots.");
System.exit(0);
}
return snapScreen();
}
public void waitTime(long milis)
{
try
{
Thread.sleep(milis);
}
catch(Exception e)
{
}
}
public static void main(String[]args)
{
new Virtual_Transparency();
}
}