绘图与动画.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
绘图与动画.ppt

繪圖與動畫 Draw/Paint Animation 設定顏色 顏色的設定有兩種方式 顏色常數 設定顏色(續) 自行指定顏色 以R(ed)G(reen)B(lue)三原色自行配製 R ? 0~255 G ? 0~255 B ? 0~255 繪圖方法 paint()方法 定義於Component類別中 要在容器上繪圖時,必須在程式中實作paint()方法,並提供一個Graphics類別的物件供繪圖之用 當元件需要繪圖時,Graphics物件g自動的傳給paint()方法 語法 public void paint(Graphics g) 畫線、矩形 畫線 drawLine(int x1, int y1, int x2, int y2) 畫矩形 drawRect(int x, int y, int width, int height) 畫實心矩形 fillRect(int x, int y, int width, int height) 畫圓角矩形 drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) 畫實心圓角矩形 fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) 畫弧、畫圓 畫弧 drawArc(int x1, int y1, int width, int height , int startangle , int arcAngle) 畫實心弧 fillArc(int x1, int y1, int width, int height , int startangle , int arcAngle) 畫圓 drawOval(int x, int y, int width, int height) 畫圓角矩形 fillOval(int x, int y, int width, int height) 畫多邊形 畫多邊線 drawPolyline(int xPoints[], int ypoints[], int npoints) 畫多邊形 drawPolygon(int xPoints[], int ypoints[], int npoints) 畫實心多邊形 fillPolygon(int xPoints[], int ypoints[], int npoints) 畫文字 drawString(String str, int x, int y) drawString(String str, float x, float y) Graphics2D類別 Graphics2D類別式一個抽象類別,繼承自Graphics類別,對幾何圖形提供「座標轉移」、「顏色控制」、「文字繪製」等等功能 提供給Graphics2D類別物件的座標是一個與設備無關的座標體系,稱為「用戶空間(user space)」,Graphics2D提供一個AffineTransform物件可將用戶空間的座標轉換為與設備有關的座標體系,稱為設備空間 每一個Graphics2D物件都結合一個GraphicsConfiguration物件,它定義繪製目標的特性,如繪點(pixel)的格式及解析度等特性 Graphics2D的主要屬性(1) paint屬性 public abstract void setPaint(Paint paint) 提供繪製圖形線條的顏色 Graphics2D的主要屬性(2) stroke屬性 public abstract void setStroke(Stroke s) 提供繪製圖形線條樣式 Graphics2D的主要屬性(2) 線條的樣式可由BasicStroke類別予以設定虛線樣式 BasicStroke(float width, int cap, int join, float miterlimit, float dash[], float dash_phase) Graphics2D的主要屬性(3) font屬性 public abstract void setFont(Font font) 提供繪製文字的字型 Graphics2D的主要屬性(4、5) transform屬性 提供繪製圖形線條的座標轉換體系 clip屬性 public abstract void setClip(int x, int y, int w, int h) 提供繪製圖形的邊界 (x, y)左上角座標 圖形寬為w、高為h Graphics2D的主要屬性(6) composite屬性 public abstract void setCompo

文档评论(0)

gshshxx + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档