import java.awt.AWTException;
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
public class TransFrame extends Frame {
private Robot robot;
private BufferedImage backImage;
private int x;
private int y;
private int width;
private int height;
public TransFrame(int x, int y, int width, int height) {
setUndecorated(true);
setBounds(x, y, width, height);
setLayout(new FlowLayout());
this.x = x;
this.y = y;
this.width = width;
this.height = height;
try {
robot = new Robot();
} catch (AWTException ex) {
ex.printStackTrace();
return;
}
Button recaptureButton = new Button("Recapture");
recaptureButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
copyScreen();
}
});
add(recaptureButton);
Button closeButton = new Button("Close");
closeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
System.exit(0);
}
});
add(closeButton);
copyScreen();
}
public void paint(Graphics g) {
g.drawImage(backImage, 0, 0, this);
}
private synchronized void copyScreen() {
hide();
try {
Thread.sleep(100L);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
backImage = robot.createScreenCapture(new Rectangle(x, y, width, height));
show();
}
public static void main(String[] args) {
int x = Integer.parseInt(args[0]);
int y = Integer.parseInt(args[1]);
int width = Integer.parseInt(args[2]);
int height = Integer.parseInt(args[3]);
new TransFrame(x, y, width, height).setVisible(true);
}
}
|