There are two ways to draw basic shapes like circles, ovals, lines, arcs, squares, rectangles, rounded rectangles, and polygons. The first is to use specific drawing methods like Graphics.drawOval(). This example uses these methods. The second is to construct a shape and then use Graphics2D.draw() to draw the shape. See the java.awt.geom package for examples that create shapes.

    // See e575 The Quintessential Drawing Program
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D)g; g2d.drawLine(x1, y1, x2, y2);
g2d.drawOval(x, y, w, h);
g2d.drawRect(x, y, w, h); // A start angle of 0 represents a 3 o'clock position, 90 represents a 12 o'clock position,
// and -90 (or 270) represents a 6 o'clock position
int startAngle = 45;
int arcAngle = -60;
g2d.drawArc(x, y, w, h, startAngle, arcAngle); g2d.drawRoundRect(x, y, w, h, arcWidth, arcHeight); Polygon polygon = new Polygon();
polygon.addPoint(x, y);
// Add more points...
g2d.drawPolygon(polygon);
}
Related Examples

e586. Drawing Simple Shapes的更多相关文章

  1. LightOJ 1285 - Drawing Simple Polygon (几何,极角排序)

    1285 - Drawing Simple Polygon   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...

  2. e591. Drawing Simple Text

    See also e575 The Quintessential Drawing Program. public void paint(Graphics g) { // Set the desired ...

  3. Drawing Simple Polygon(Create Simple Polygon from unordered points by angle sorting)

    Keywords: 极角排序, Simple Polygon Generation Given set of points in the plane, your task is to draw a p ...

  4. LightOj1285 - Drawing Simple Polygon(连接多边形各点)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1285 题意:给你一些点,然后把它们用一条线把它们连起来,构成一个多边形,不能有相交,必 ...

  5. e575. The Quintessential Drawing Program

    To draw on the screen, it is first necessary to subclass a JComponent and override its paint() metho ...

  6. e577. Enabling Antialiasing

    // See e575 The Quintessential Drawing Program public void paint(Graphics g) { // Retrieve the graph ...

  7. python编程学习--Pygame - Python游戏编程入门(0)---转载

    原文地址:https://www.cnblogs.com/wuzhanpeng/p/4261015.html 引言 博客刚开,想把最近学习的东西记录下来,算是一种笔记.最近打算开始学习Python,因 ...

  8. Pygame - Python游戏编程入门(0) 转

    博客刚开,想把最近学习的东西记录下来,算是一种笔记.最近打算开始学习Python,因为我感觉Python是一门很有意思的语言,很早以前就想学了(碍于懒),它的功能很强大,你可以用它来做科学运算,或者数 ...

  9. Pygame - Python游戏编程入门

    >>> import pygame>>> print(pygame.ver)1.9.2a0 如果没有报错,应该是安装好了~ 如果报错找不到模块,很可能是安装版本的问 ...

随机推荐

  1. php - 时间操作

    ini_set('date.timezone','Asia/Shanghai'); http://www.w3school.com.cn/php/func_date_strtotime.asp str ...

  2. putty设置用key自动登录

    1.在Linux下ssh-keygen -t rsa 生成密钥对 2.把私钥id_isa下载到用scp下载到windows并用puttygen加载并重新保存私钥. 3.在windows下新建快捷方式, ...

  3. 翻翻git之---效果鲜明的类ViewPager库 ConvenientBanner(对图片载入部分进行改动)

    转载请注明出处:王亟亟的大牛之路 昨天写了篇基础的View绘制的内容貌似观众老爷们不怎么喜欢.那再这里再安利下自己定义View时.用到Paint Canvas的一些温故.讲讲用路径绘画实现动画效果(基 ...

  4. SqlServer 如何知道是否发生了索引碎片

    --如何知道是否发生了索引碎片 SELECT object_name(dt.object_id) Tablename,si.name IndexName,dt.avg_fragmentation_in ...

  5. 利用ForgeryPy生成虚拟数据

    在程序研发过程中,我们往往需要大量的虚拟实验数据.Python中有多个包可以用于生成虚拟数据,其中功能较为完善的是ForgeryPy. 1 安装 采用pip进行安装: pip install Forg ...

  6. 孙鑫VC++视频教程笔记

    写在前面的话:在学习孙鑫老师的VC++视频时,为了加深自己对知识的深入理解,就做了下面的笔记. 第一讲: 第二讲: 第三讲: 第四讲: 第五讲: 第六讲: 第七讲: 第八讲: 第九讲: 第十讲: 第十 ...

  7. Ubuntu和Busybox下用make menuconfig配置出错解决

    http://blog.csdn.net/satiling/article/details/6965985 # make menuconfig In file included from script ...

  8. 在jsp里面不要瞎用<!-- -->注释

    如图: SEVERE: Servlet.service() for servlet jsp threw exceptionorg.apache.jasper.JasperException: /ch1 ...

  9. uC/OS-III 概要

    本章主要对 uC/OS-III 实时操作系统做一些概要介绍,使读者对 uC/OS-III 有个整体的浅 认识,为后面的章节的详细讲解做一个铺垫. 下图是 uC/OS-III 系统从底层到上层的文件结构 ...

  10. dp之二维背包poj1837(天平问题 推荐)

    题意:给你c(2<=c<=20)个挂钩,g(2<=g<=20)个砝码,求在将所有砝码(砝码重1~~25)挂到天平(天平长  -15~~15)上,并使得天平平衡的方法数..... ...