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

Java中的Canvas绘图源码实例

于 2023-04-11 发布 文件大小:45.60 kB
0 64
下载积分: 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 个回复

  • 影院售票系统完整源码,图形化售票、退票、预定票直观明了...
    影院售票系统完整源码,图形化售票、退票、预定票直观明了-cinema ticketing system integrity source, graphical tickets, refunds, scheduled votes intuitive understanding
    2022-06-28 08:57:56下载
    积分:1
  • VB制作
    VB制作--不可思议的3D飞机游戏,好东西-VB production-- incredible 3D aircraft games, good things
    2022-05-24 23:29:10下载
    积分:1
  • This is a knockout mice similar to the game, I hope you would like to common sen...
    这个也是敲地鼠类似的游戏,希望大家喜欢,来常识一下吧-This is a knockout mice similar to the game, I hope you would like to common sense about it
    2022-10-31 00:45:03下载
    积分:1
  • 串口调试,绿色软件。不需要安装..易于使用调试器
    串口调试,绿色软件。无须安装即可使用.. 方便调试程序-Serial debugging, green software. Do not need to install .. easy to use debugger
    2022-01-26 08:25:59下载
    积分:1
  • flashp A comparison of the flash of burning practical tools. Commissioning tests...
    flashp是一款比较实用的flash烧写工具. 试验调试时使用非常方便.-flashp A comparison of the flash of burning practical tools. Commissioning tests very convenient to use.
    2022-04-06 13:22:13下载
    积分:1
  • 本文介绍了在自由口通信模式下,用计算机读写S7
    本文介绍了在自由口通信模式下,用计算机读写S7-200 PLC存储区内相邻的多个字 节数据的通信程序设计方法,程序设计中采用了多种可靠性措施。 -In this paper, in a free port communication mode, using the computer to read and write S7-200 PLC storage area adjacent to a number of bytes of data communication program design methods, procedures designed to use a variety of reliability measures.
    2022-01-22 03:49:14下载
    积分:1
  • arcpad二次开发示例,电力GIS系统巡视PDA模块
    arcpad二次开发示例,电力GIS系统巡视PDA模块-arcpad secondary development examples, the power of GIS inspections PDA Module
    2022-01-25 19:58:35下载
    积分:1
  • 是程序计算从选定的点的地形图的可见性。我..
    这个程序可以计算给定点处的小区信号范围覆盖。-is program computes a map of visibility from a selected point on a topography. It has been written to help the search for radio relay best location. Because it considers only direct line of sight, it gives a good estimation for possible radio link for short distances only (less than 10 km), neglecting curvature of the Earth, Fresnel zone and atmospheric refraction on radio waves propagation. The program computes the relative elevation angle of the mask for each point (the angle is null or negative if the point is visible). The function needs a digital elevation model Z and associated (X,Y) vectors or matrices of coordinates (same unit as Z), position of the point (X0,Y0), the antenna height H0 (for instance 4 m), and the hypothetic antenna height Ha on each topography points (for instance 3 m). When no output argument is given, the function plots a map of the results (color map of mask angles, and blank for visible points, see example screenshot). The s
    2022-06-27 17:42:17下载
    积分:1
  • 2005首届大学生程序设计大赛试题....哈,可以练练手
    2005首届大学生程序设计大赛试题....哈,可以练练手-2005 First Collegiate Programming Contest questions .... Ha, you can hand练练
    2022-03-12 12:51:11下载
    积分:1
  • matlab program bag, read & write netcdf file
    matlacb程序包,能读写netcdf文件,-matlab program bag, read & write netcdf file
    2022-11-22 18:05:04下载
    积分:1
  • 696518资源总数
  • 104269会员总数
  • 31今日下载