035 |
Robot robot = new Robot(); |
036 |
BufferedImage img = robot.createScreenCapture( new Rectangle(c1, c2,w,h)); |
037 |
File save_path= new File( "screen1.jpg" ); |
038 |
ImageIO.write(img, "JPG" , save_path); |
039 |
System.out.println( "Cropped image saved successfully." ); |
040 |
} |
041 |
@Override |
042 |
public void mouseClicked(MouseEvent arg0) { |
043 |
} |
044 |
045 |
@Override |
046 |
public void mouseEntered(MouseEvent arg0) { |
047 |
} |
048 |
049 |
@Override |
050 |
public void mouseExited(MouseEvent arg0) { |
051 |
} |
052 |
053 |
@Override |
054 |
public void mousePressed(MouseEvent arg0) { |
055 |
repaint(); |
056 |
c1=arg0.getX(); |
057 |
c2=arg0.getY(); |
058 |
} |
059 |
060 |
@Override |
061 |
public void mouseReleased(MouseEvent arg0) { |
062 |
repaint(); |
063 |
if (drag_status== 1 ) |
064 |
{ |
065 |
c3=arg0.getX(); |
066 |
c4=arg0.getY(); |
067 |
try |
068 |
{ |
069 |
draggedScreen(); |
070 |
} |
071 |
catch (Exception e) |
072 |
{ |
073 |
e.printStackTrace(); |
074 |
} |
075 |
} |
076 |
} |
077 |
078 |
@Override |
079 |
public void mouseDragged(MouseEvent arg0) { |
080 |
repaint(); |
081 |
drag_status= 1 ; |
082 |
c3=arg0.getX(); |
083 |
c4=arg0.getY(); |
084 |
} |
085 |
086 |
@Override |
087 |
public void mouseMoved(MouseEvent arg0) { |
088 |
089 |
} |
090 |
091 |
public void paint(Graphics g) |
092 |
{ |
093 |
super .paint(g); |
094 |
int w = c1 - c3; |
095 |
int h = c2 - c4; |
096 |
w = w * - 1 ; |
097 |
h = h * - 1 ; |
098 |
if (w< 0 ) |
099 |
w = w * - 1 ; |
100 |
g.drawRect(c1, c2, w, h); |
101 |
} |
102 |
} |
全文完!