Java 怎么画圆边

2019年8月20日22:29:29 评论 33

1.简介

Java 怎么画圆边?——请看下文。

2.代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */


import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;

public class Main {
    public static void drawRoundEdge(Graphics g, Color color, int x, int y,
            int width, int height, boolean down, boolean fade) {
        Graphics2D g2 = (Graphics2D) g;
        int radius = height / 2;

        Paint oldPaint = g2.getPaint();
        Paint paint = color;

        if (fade) {
            Color color2 = new Color(color.getRed(), color.getGreen(),
                    color.getBlue(), 0);
            if (down) {
                paint = new GradientPaint(x, y, color, x, y + radius,
                        color2, false);
            } else {
                paint = new GradientPaint(x, y - radius, color2, x, y,
                        color, false);
            }

        }
        g2.setPaint(paint);

        
        int lineWidth = width - height + 1;
        int lineX = x + radius;
        g.drawLine(lineX, y, lineX + lineWidth, y);

        
        int arcY = down ? y : y - height + 1;
        int start = down ? 90 : 180;
        g.drawArc(x, arcY, height - 1, height - 1, start, 90);

        
        start = down ? 0 : 270;
        g.drawArc(x + lineWidth, arcY, height - 1, height - 1, start, 90);

        g2.setPaint(oldPaint);
    }
}

 

3.总结

示例代码演示了 Java 怎么画圆边,具体步骤参见示例代码。

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: