分享JAVA做的类似QQ截图代码>_< 大家来顶下!

Jacky_Zhu_1983 2009-01-22 04:25:28
来和大家一起分享下我的代码...
有不足之处大家指正! >_<

另外还有一篇
"Hibernate配置1对多,插入等问题的demo "
是hibernate一对多,多对一插入的一个事例.
请大家多多指教! >_<
...全文
2687 72 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
72 条回复
切换为时间正序
请发表友善的回复…
发表回复
anyanlongA 2012-05-24
  • 打赏
  • 举报
回复
Uncaught error fetching image:
java.lang.NullPointerException
at sun.awt.image.URLImageSource.getConnection(URLImageSource.java:99)
at sun.awt.image.URLImageSource.getDecoder(URLImageSource.java:113)
at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:240)
at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:172)
at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)
什么错啊这是
ZJW445253545 2011-11-18
  • 打赏
  • 举报
回复
[Quote=引用 49 楼 sincereme 的回复:]
jf.getContentPane().add(new Temp(jf, bi, di.width, di.height));

public void mouseClicked(MouseEvent me) {
if (me.getClickCount() == 2) {
// Rectangle rec=new
// Rectangle(startX,startY,Math.abs(……
[/Quote]
同上,有错!~~
索隆 2011-10-20
  • 打赏
  • 举报
回复
很强大!
  • 打赏
  • 举报
回复
非常感谢楼主的无私奉献!!!!!!
落落2015 2010-11-11
  • 打赏
  • 举报
回复
好像右键无法取消。。
nvrenbumeigaga 2010-09-02
  • 打赏
  • 举报
回复
谢谢分享,
fblwjp 2010-09-02
  • 打赏
  • 举报
回复
谢谢版主!!
zjlzlr 2010-08-20
  • 打赏
  • 举报
回复
如何引用呀?
zjlzlr 2010-08-20
  • 打赏
  • 举报
回复
我不用纯java,jsp+servlet程序里该杂实现呀?可否用该例子呀?
kingwinboss 2010-08-20
  • 打赏
  • 举报
回复
膜拜中 但是吧 怎么运行呢 我拷到机器上好多错误呀
henrychen2002 2010-03-24
  • 打赏
  • 举报
回复
以上错误是因为你们没有放014.png到class目录下。


--------------------------------
为啥你这个截屏的时候还可以按alt+tab键切换桌面内容呢?如何解决呢?
cuixiuqin1954 2010-03-19
  • 打赏
  • 举报
回复
我也是这个错误……
jinhuaqj 2010-03-19
  • 打赏
  • 举报
回复
运行是这个错误,请教如何解决,谢谢啊

Uncaught error fetching image:
java.lang.NullPointerException
at sun.awt.image.URLImageSource.getConnection(URLImageSource.java:97)
at sun.awt.image.URLImageSource.getDecoder(URLImageSource.java:106)
at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:240)
at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:172)
at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)
xingzibird 2010-03-02
  • 打赏
  • 举报
回复
可不可以把能运行的贴出来啊?
cuixiuqin1954 2010-02-25
  • 打赏
  • 举报
回复
我运行有错请大家指点
gybdkdc 2010-01-26
  • 打赏
  • 举报
回复
哦,LZ真的强,也很无私啊!
  • 打赏
  • 举报
回复
UP一定要顶
liudong8510 2010-01-12
  • 打赏
  • 举报
回复
把楼主的代码整理了下,能运行,谢谢了!
liudong8510 2010-01-12
  • 打赏
  • 举报
回复
public void mouseDragged(MouseEvent me){
int x=me.getX();
int y=me.getY();
if(current==States.MOVE){
startX+=(x-tempX);
startY+=(y-tempY);
endX+=(x-tempX);
endY+=(y-tempY);
tempX=x;
tempY=y;
}else if(current==States.EAST){
if(startX>endX){
startX+=(x-tempX);
tempX=x;
} else{
endX+=(x-tempX);
tempX=x;
}
}else if(current==States.NORTH){
if(startY<endY){
startY+=(y-tempY);
tempY=y;
}else{
endY+=(y-tempY);
tempY=y;
}
}else if(current==States.WEST){
if(startX<endX){
startX+=(x-tempX);
tempX=x;
} else{
endX+=(x-tempX);
tempX=x;
}
}else if(current==States.SOUTH){
if(startY>endY){
startY+=(y-tempY);
tempY=y;
}else{
endY+=(y-tempY);
tempY=y;
}
} else if(current==States.NORTH_EAST){
if(startX>endX){
startX+=(x-tempX);
tempX=x;
} else{
endX+=(x-tempX);
tempX=x;
}
if(startY<endY){
startY+=(y-tempY);
tempY=y;
}else{
endY+=(y-tempY);
tempY=y;
}
}else if(current==States.NORTH_WEST){
if(startX<endX){
startX+=(x-tempX);
tempX=x;
} else{
endX+=(x-tempX);
tempX=x;
}
if(startY<endY){
startY+=(y-tempY);
tempY=y;
}else{
endY+=(y-tempY);
tempY=y;
}
}else if(current==States.SOUTH_EAST){
if(startY>endY){
startY+=(y-tempY);
tempY=y;
}else{
endY+=(y-tempY);
tempY=y;
}
if(startX>endX){
startX+=(x-tempX);
tempX=x;
} else{
endX+=(x-tempX);
tempX=x;
}
}else if(current==States.SOUTH_WEST){
if(startY>endY){
startY+=(y-tempY);
tempY=y;
}else{
endY+=(y-tempY);
tempY=y;
}
if(startX<endX){
startX+=(x-tempX);
tempX=x;
} else{
endX+=(x-tempX);
tempX=x;
}
}
else{
startX=tempX;
startY=tempY;
endX=me.getX();
endY=me.getY();
}
this.repaint();
}

public void mousePressed(MouseEvent me){
tempX=me.getX();
tempY=me.getY();
}

public void mouseReleased(MouseEvent me){
System.out.println("mouseReleased");
if(me.isPopupTrigger()){
if(current==States.MOVE){
startX=0;
startY=0;
endX=0;
endY=0;
repaint();
} else{
jf.dispose();
//doSave();

}
}
}

public void mouseClicked(MouseEvent me){
if(me.getClickCount()==2){
//Rectangle rec=new Rectangle(startX,startY,Math.abs(endX-startX),Math.abs(endY-startY));
Point p=me.getPoint();
if(select.contains(p)){
if(select.x+select.width<this.getWidth()&&select.y+select.height<this.getHeight()){
get=bi.getSubimage(select.x,select.y,select.width,select.height);
jf.dispose();
//save.setEnabled(true);
doSave();
}else{
int wid=select.width,het=select.height;
if(select.x+select.width>=this.getWidth()){
wid=this.getWidth()-select.x;
}
if(select.y+select.height>=this.getHeight()){
het=this.getHeight()-select.y;
}
get=bi.getSubimage(select.x,select.y,wid,het);
jf.dispose();
//save.setEnabled(true);
doSave();
}
}
}
}
private void doSave()throws NullPointerException{
try{

File file = new File("d:/temp/123.jpg");//这里我写死了路径和类型jpg
String about="jpg";
String ext=file.toString().toLowerCase();
System.out.println(ext);

ImageIO.write(get,about,file);
} catch(Exception exe){
exe.printStackTrace();
}
}


}
liudong8510 2010-01-12
  • 打赏
  • 举报
回复
public class CaptureScreen extends JPanel implements ActionListener,MouseListener,MouseMotionListener{
/**
*
*/
private JButton start,cancel,save;
private BufferedImage bi;
public BufferedImage get;
private int width,height;
private int startX,startY,endX,endY,tempX,tempY;
private JFrame jf;
private Rectangle select=new Rectangle(0,0,0,0);//表示选中的区域
private Cursor cs;//表示一般情况下的鼠标状态
private States current=States.DEFAULT;// 表示当前的编辑状态
private Rectangle[] rec;//表示八个编辑点的区域


public static void main(String args[]){
new CaptureScreen();
}

public CaptureScreen(){
doStart();
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource()==start){
doStart();
} else if(ae.getSource()==cancel){
//System.exit(0);
} else if(ae.getSource()==save){
doSave();
}
}
private void doStart(){
try{
Robot ro=new Robot();
Toolkit tk=Toolkit.getDefaultToolkit();
Dimension di=tk.getScreenSize();
Rectangle rec=new Rectangle(0,0,di.width,di.height);
BufferedImage bi=ro.createScreenCapture(rec);
JFrame jf=new JFrame();
initRecs();
jf.getContentPane().add(new CaptureScreen(jf,bi,di.width,di.height));
jf.setUndecorated(true);
jf.setSize(di);
jf.setVisible(true);
jf.setAlwaysOnTop(true);
}catch(Exception exe){
exe.printStackTrace();
}
}

public CaptureScreen(JFrame jf,BufferedImage bi,int width,int height){
this.jf=jf;
this.bi=bi;
this.width=width;
this.height=height;
this.addMouseListener(this);
this.addMouseMotionListener(this);
Image icon=Toolkit.getDefaultToolkit().createImage(this.getClass().getResource("014.png"));
cs=Toolkit.getDefaultToolkit().createCustomCursor(icon,new Point(0,0),"icon");
this.setCursor(cs);
initRecs();
}

private void initRecs(){
rec=new Rectangle[8];
for(int i=0;i<rec.length;i++){
rec[i]=new Rectangle();
}
}

public void paintComponent(Graphics g){
g.drawImage(bi,0,0,width,height,(ImageObserver) this);
g.setColor(Color.RED);
g.drawLine(startX,startY,endX,startY);
g.drawLine(startX,endY,endX,endY);
g.drawLine(startX,startY,startX,endY);
g.drawLine(endX,startY,endX,endY);
int x=startX<endX?startX:endX;
int y=startY<endY?startY:endY;
select=new Rectangle(x,y,Math.abs(endX-startX),Math.abs(endY-startY));
int x1=(startX+endX)/2;
int y1=(startY+endY)/2;
g.fillRect(x1-2,startY-2,5,5);
g.fillRect(x1-2,endY-2,5,5);
g.fillRect(startX-2,y1-2,5,5);
g.fillRect(endX-2,y1-2,5,5);
g.fillRect(startX-2,startY-2,5,5);
g.fillRect(startX-2,endY-2,5,5);
g.fillRect(endX-2,startY-2,5,5);
g.fillRect(endX-2,endY-2,5,5);
rec[0]=new Rectangle(x-5,y-5,10,10);
rec[1]=new Rectangle(x1-5,y-5,10,10);
rec[2]=new Rectangle((startX>endX?startX:endX)-5,y-5,10,10);
rec[3]=new Rectangle((startX>endX?startX:endX)-5,y1-5,10,10);
rec[4]=new Rectangle((startX>endX?startX:endX)-5,(startY>endY?startY:endY)-5,10,10);
rec[5]=new Rectangle(x1-5,(startY>endY?startY:endY)-5,10,10);
rec[6]=new Rectangle(x-5,(startY>endY?startY:endY)-5,10,10);
rec[7]=new Rectangle(x-5,y1-5,10,10);
}

public void mouseMoved(MouseEvent me){
if(select.contains(me.getPoint())){
this.setCursor(new Cursor(Cursor.MOVE_CURSOR));
current=States.MOVE;
} else{
States[] st=States.values();
for(int i=0;i<rec.length;i++){
if(rec[i].contains(me.getPoint())){
current=st[i];
this.setCursor(st[i].getCursor());
return;
}
}
this.setCursor(cs);
current=States.DEFAULT;
}
}

public void mouseExited(MouseEvent me){

}

public void mouseEntered(MouseEvent me){

}
加载更多回复(52)

81,117

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧