登录
首页 » 其他 » Java中的Canvas绘图源码实例

Java中的Canvas绘图源码实例

于 2023-04-11 发布 文件大小:45.60 kB
0 157
下载积分: 2 下载次数: 1

代码说明:

Java中的Canvas绘图源码实例,主要是画线条、弧线、圆角矩形、三角形、文字、圆形等简单的几何图形,主要是通过创建DrawingCanvas对象canvas,为canvas设置命令监听者,实现接口CommandListener的方法,把缓冲区图像的内容绘制到画布上,画图部分代码:   int w = getWidth(); // 画布的宽度   int h = getHeight(); // 画布的高度   Image buffer = Image.createImage(w, h); // 用于绘图的缓冲图像   Graphics gc = buffer.getGraphics(); // 获取缓冲图像的图形环境   // 清除画布   public void clearScreen() {    gc.setColor(255,255,255); // 设置绘图颜色为白色    gc.fillRect(0,0,w,h); // 把缓冲图像填充为白色    gc.setColor(255,0,0); // 设置绘图颜色为红色   }   // 绘制直线   public void drawLine() {    setTitle("直线"); // 设置画布的标题    clearScreen(); // 清除画布    gc.drawLine(10,10,w-20,h-20); // 绘制黑色直线    gc.setColor(0,0,255); // 设置绘图颜色为蓝色    gc.drawLine(10,h/2,w-10,h/2); // 绘制蓝色直线   }   // 绘制弧   public void drawArc() {    setTitle("弧线和填充弧");    clearScreen();    gc.drawArc(5,5,w/2-20,h/2-20,60,216); // 绘制弧线    gc.drawArc(5,h/2-10,w/2-20,h/2-20,0,360); // 绘制圆    gc.setColor(0,0,255);    gc.fillArc(w/2,5,w/2-20,h/2-20,60,216); // 绘制填充弧线    gc

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • 能够进行小游戏如魔板游戏.包括有数字玩法,图像玩法
    能够进行小游戏如魔板游戏.包括有数字玩法,图像玩法-to small board games, such as Magic games. Figures include rules of images Play
    2022-02-05 15:38:26下载
    积分:1
  • lm35原理图以及程序
    lm35原理图以及程序-lm35 schematics and procedures
    2022-10-19 16:55:03下载
    积分:1
  • SEGY read the original code, the program is an essential exploration software co...
    segy读取原码,该程序是勘探软件必备的代码,有做石油方面项目的一定有用。-SEGY read the original code, the program is an essential exploration software code, so oil projects necessarily useful.
    2022-03-18 14:43:13下载
    积分:1
  • C#注销登录、关机 重启电脑的程序源码
    C#注销登录、关机 重启电脑的程序源码,主要就是完成这几个完成,调用ExitWindowsEx函数、定义process对象实例、执行关机命令、执行重新启动计算机命令、设置Process对象的Start()方法的属性,您可以通过本源码实例了解一些C#与Windows相关函数之间的调用方法。
    2022-05-15 23:27:02下载
    积分:1
  • 离散优化问题的启发式设计与实现,…
    When designing and implementing heuristics for discrete optimization problems, there are many choices to be made. These include search paradigms, search mechanisms, search parameters, test sets, etc. Often these choices are treated as independent of each other, even though most researchers acknowledge some interdependence between the diff erent search mechanisms and associated para- meter settings. Our experience is that the search mechanisms and parameters often interact, and at times in unforeseen ways. This is a diffi cult problem to disentangle, and often even to discover.
    2022-06-20 23:25:41下载
    积分:1
  • HTML for the web代码for the
    Code for the html for the web
    2022-02-14 00:30:41下载
    积分:1
  • NEC controller chip, 09 Electronic Design Contest will use the data very well, t...
    NEC控制芯片,09电子设计大赛必用,很好的资料,虽然不是我写的,但是肯定有用-NEC controller chip, 09 Electronic Design Contest will use the data very well, though I did not write, but certainly useful for
    2022-01-21 23:58:30下载
    积分:1
  • Experimental purposes and requirements of one. Master view, rename and delete us...
    实验目的和要求 1.掌握查看、重命名及删除用户定义的数据类型的方法。 2.掌握向表中添加、删除及修改数据的方法。 3。综合实验结果 -Experimental purposes and requirements of one. Master view, rename and delete user-defined data type method. 2. Master to the table to add, delete and modify data. 3. Comprehensive experimental results
    2022-03-23 01:23:17下载
    积分:1
  • 新书《python开发技术详解》的光盘上的源代码。
    新书《python开发技术详解》的光盘上的源代码。-Book 《python development technologies Xiang Jie》 CD-ROM on the source code.
    2022-05-06 19:13:37下载
    积分:1
  • abaqus explosion simulation* Heading** Job name: cbs Model name: Model
    abaqus 爆炸模拟 *Heading ** Job name: cbs Model name: Model-1 *Preprint, echo=NO, model=NO, history=NO, contact=NO ** ** PARTS ** *Part, name=Part-1 *Node-abaqus explosion simulation* Heading** Job name: cbs Model name: Model-1* Preprint, echo = NO, model = NO, history = NO, contact = NO**** PARTS*** Part, name = Part-1* Node
    2023-07-12 12:50:04下载
    积分:1
  • 696516资源总数
  • 106914会员总数
  • 0今日下载