- /*
- * Loupe.java
- *
- * Créé le 14-08-2006, 12:14
- *
- */
-
-
- import javax.swing.* ;
- import java.awt.* ;
- import java.awt.image.* ;
-
- /**
- * Auteur : A.B.
- */
-
- public class Loupe extends JFrame implements Runnable {
-
- /**
- * Données membres
- */
- private BufferedImage image = null;
-
- /** constructeur de la classe Loupe */
- public Loupe() {
- super ("Loupe");
- setDefaultCloseOperation (EXIT_ON_CLOSE);
- setResizable (false);
- setBounds (50, 50, 250, 250);
-
- setVisible (true);
- }
-
- /**
- * faire un imprime écran une zone rectangulaire de centre la pointe du
- * curseur
- */
- public void getScreenShot (Point point) throws AWTException {
- getScreenShot (point.x, point.y);
- return;
- }
-
- /**
- * faire un imprime écran d'une zone rectangulaire de centre la pointe du
- * curseur avec un facteur d'aggrandissment x2
- */
- public void getScreenShot (int x, int y) throws AWTException {
- int sourceWidth = getWidth () / 2;
- int sourceHeight = getHeight () / 2;
-
- Robot robot;
- robot = new Robot ();
-
- Rectangle rectangle;
- rectangle = new Rectangle (x - (sourceWidth >> 1),
- y - (sourceHeight >> 1),
- sourceWidth,
- sourceHeight);
-
- image = robot.createScreenCapture (rectangle);
-
- return;
- }
-
- /**
- * @param point : (x, y)
- * renvoie : true si ce point est à l'intérieur de la fenêtre
- * false sinon
- */
- boolean isPointInRect (Point point) {
- int frameX = getX ();
- int frameY = getY ();
- int frameWidth = getWidth ();
- int frameHeight = getHeight ();
-
- return ((point.x >= frameX) & (point.x <= frameX + frameWidth)) &
- (point.y >= frameY) & (point.y <= frameY + frameHeight);
- }
-
- /**
- *
- */
- public void run () {
- while (true) {
- try {
- // récupérer les coordonnées de la pointe de la souris
- Point point;
- point = MouseInfo.getPointerInfo ().getLocation ();
-
- if (isPointInRect (point))
- continue;
-
- Graphics g;
- g = getGraphics ();
-
- // faire un imprime écran
- try {
- getScreenShot (point);
- }
- catch (AWTException exception) {
- }
- // afficher l'imprime écran sur le fenêtre
- if (image != null)
- g.drawImage (image, 0, 0, getWidth (), getHeight (), this);
- // libérer le contexte d'affichage
- g.dispose ();
- // faire un rafraîchissement tout les 50 millisecondes
- Thread.sleep (50);
- }
- catch (InterruptedException exception) {
- }
- }
- }
-
- /**
- * @param args : ligne de commande
- */
- public static void main(String[] args) {
- // code de l'application
- Thread Application = new Thread ( new Loupe ());
- Application.start ();
- }
- }
/*
* Loupe.java
*
* Créé le 14-08-2006, 12:14
*
*/
import javax.swing.* ;
import java.awt.* ;
import java.awt.image.* ;
/**
* Auteur : A.B.
*/
public class Loupe extends JFrame implements Runnable {
/**
* Données membres
*/
private BufferedImage image = null;
/** constructeur de la classe Loupe */
public Loupe() {
super ("Loupe");
setDefaultCloseOperation (EXIT_ON_CLOSE);
setResizable (false);
setBounds (50, 50, 250, 250);
setVisible (true);
}
/**
* faire un imprime écran une zone rectangulaire de centre la pointe du
* curseur
*/
public void getScreenShot (Point point) throws AWTException {
getScreenShot (point.x, point.y);
return;
}
/**
* faire un imprime écran d'une zone rectangulaire de centre la pointe du
* curseur avec un facteur d'aggrandissment x2
*/
public void getScreenShot (int x, int y) throws AWTException {
int sourceWidth = getWidth () / 2;
int sourceHeight = getHeight () / 2;
Robot robot;
robot = new Robot ();
Rectangle rectangle;
rectangle = new Rectangle (x - (sourceWidth >> 1),
y - (sourceHeight >> 1),
sourceWidth,
sourceHeight);
image = robot.createScreenCapture (rectangle);
return;
}
/**
* @param point : (x, y)
* renvoie : true si ce point est à l'intérieur de la fenêtre
* false sinon
*/
boolean isPointInRect (Point point) {
int frameX = getX ();
int frameY = getY ();
int frameWidth = getWidth ();
int frameHeight = getHeight ();
return ((point.x >= frameX) & (point.x <= frameX + frameWidth)) &
(point.y >= frameY) & (point.y <= frameY + frameHeight);
}
/**
*
*/
public void run () {
while (true) {
try {
// récupérer les coordonnées de la pointe de la souris
Point point;
point = MouseInfo.getPointerInfo ().getLocation ();
if (isPointInRect (point))
continue;
Graphics g;
g = getGraphics ();
// faire un imprime écran
try {
getScreenShot (point);
}
catch (AWTException exception) {
}
// afficher l'imprime écran sur le fenêtre
if (image != null)
g.drawImage (image, 0, 0, getWidth (), getHeight (), this);
// libérer le contexte d'affichage
g.dispose ();
// faire un rafraîchissement tout les 50 millisecondes
Thread.sleep (50);
}
catch (InterruptedException exception) {
}
}
}
/**
* @param args : ligne de commande
*/
public static void main(String[] args) {
// code de l'application
Thread Application = new Thread ( new Loupe ());
Application.start ();
}
}