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 49 50 51 52 53 54 55 56 57 58 59 60 61
|
<div style="margin-left:40px">...</div>
<div style="margin-left:40px">public void updateImageDesktop()</div><div style="margin-left:40px">{</div><div style="margin-left:40px"><div style="margin-left:40px">imageBureau = robot.createScreenCapture (new Rectangle(0,0,ecran.width,ecran.height));</div></div><div style="margin-left:40px">}</div>...
public void paint(Graphics g)
{
if(buffer == null) {
image = createImage(GUI.WIDHT_LOUPE,GUI.HEIGHT_LOUPE);
buffer = image.getGraphics();
}
buffer.clearRect(0,0,GUI.WIDHT_LOUPE,GUI.HEIGHT_LOUPE);
point = MouseInfo.getPointerInfo().getLocation();
int[] p = imageNotOutside(point.x-(GUI.WIDHT_LOUPE/2),point.y-(GUI.HEIGHT_LOUPE/2));
img = imageBureau.getSubimage(p[0], p[1], GUI.WIDHT_LOUPE, GUI.HEIGHT_LOUPE);
img = couleur.getImageModifiee(img, GUI.WIDHT_LOUPE, GUI.HEIGHT_LOUPE, choix);
setLocation(point.x-(GUI.WIDHT_LOUPE/2),point.y-(GUI.HEIGHT_LOUPE/2));
AffineTransform transformationZoom = AffineTransform.getScaleInstance(GUI.echelle, GUI.echelle);
((Graphics2D)buffer).drawImage(img,transformationZoom,null);
g.drawImage(image,0,0,this);
}
...
public void run()
{
while (true)
{
try
{
if(!waiting)
{
repaint();
// Rafraîchissement toutes les 5 millisecondes
Thread.sleep (5);
}
}
catch (InterruptedException exception) {
}
}
}
...
public void mouseClicked(MouseEvent arg0) {
if (SwingUtilities.isLeftMouseButton(arg0))
{
if(!waiting && isVisible()) //waiting est un variable booléenne qui dit si la loupe est active ou pas
{
setVisible(false);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
updateImageDesktop();
setVisible(true);
}
}
} |
Partager