双缓冲绘制无闪烁

双缓冲绘制无闪烁

ID:15419009

大小:25.50 KB

页数:4页

时间:2018-08-03

双缓冲绘制无闪烁_第1页
双缓冲绘制无闪烁_第2页
双缓冲绘制无闪烁_第3页
双缓冲绘制无闪烁_第4页
资源描述:

《双缓冲绘制无闪烁》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、importjava.awt.BasicStroke;importjava.awt.BorderLayout;importjava.awt.Color;importjava.awt.Dimension;importjava.awt.Graphics;importjava.awt.Graphics2D;importjava.awt.Rectangle;importjava.awt.event.MouseEvent;importjava.awt.event.MouseListener;importjava.awt.event.MouseMotionList

2、ener;importjava.awt.event.WindowAdapter;importjava.awt.event.WindowEvent;importjava.awt.image.BufferedImage;importjavax.swing.JFrame;importjavax.swing.JPanel;publicclassBufferedDrawextendsJPanelimplementsMouseListener,MouseMotionListener{Rectanglerect=newRectangle(0,0,100,50);Bu

3、fferedImagebi=newBufferedImage(5,5,BufferedImage.TYPE_INT_RGB);Graphics2Dbig;intlast_x,last_y;booleanfirstTime=true;Rectanglearea;booleanpressOut=false;publicBufferedDraw(){setBackground(Color.white);addMouseMotionListener(this);addMouseListener(this);}//Handlestheeventoftheuser

4、pressingdownthemousebutton.publicvoidmousePressed(MouseEvente){last_x=rect.x-e.getX();last_y=rect.y-e.getY();//Checkswhetherornotthecursorisinsideoftherectanglewhilethe//userispressingthemouse.if(rect.contains(e.getX(),e.getY())){updateLocation(e);}else{pressOut=true;}}//Handles

5、theeventofauserdraggingthemousewhileholdingdownthe//mousebutton.publicvoidmouseDragged(MouseEvente){if(!pressOut){updateLocation(e);}}//Handlestheeventofauserreleasingthemousebutton.publicvoidmouseReleased(MouseEvente){if(rect.contains(e.getX(),e.getY())){updateLocation(e);}}pub

6、licvoidmouseMoved(MouseEvente){}publicvoidmouseClicked(MouseEvente){}publicvoidmouseExited(MouseEvente){}publicvoidmouseEntered(MouseEvente){}publicvoidupdateLocation(MouseEvente){rect.setLocation(last_x+e.getX(),last_y+e.getY());repaint();}publicvoidpaint(Graphicsg){update(g);}

7、publicvoidupdate(Graphicsg){Graphics2Dg2=(Graphics2D)g;if(firstTime){Dimensiondim=getSize();intw=dim.width;inth=dim.height;area=newRectangle(dim);bi=(BufferedImage)createImage(w,h);big=bi.createGraphics();rect.setLocation(w/2-50,h/2-25);big.setStroke(newBasicStroke(8.0f));firstT

8、ime=false;}big.setColor(Color.white);big.clearR

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。