码迷,mamicode.com
首页 > Windows程序 > 详细

e586. Drawing Simple Shapes

时间:2018-09-06 10:52:35      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:rap   rectangle   pre   lsp   java.awt   clock   s2d   his   bsp   

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

标签:rap   rectangle   pre   lsp   java.awt   clock   s2d   his   bsp   

原文地址:https://www.cnblogs.com/borter/p/9596072.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!