在 Swing 中显示图形17 Mar 2025 | 阅读 2 分钟 java.awt.Graphics 类提供了许多用于图形编程的方法。 |
Graphics 类的常用方法- public abstract void drawString(String str, int x, int y): 用于绘制指定的字符串。
- public void drawRect(int x, int y, int width, int height): 绘制具有指定宽度和高度的矩形。
- public abstract void fillRect(int x, int y, int width, int height): 用于使用默认颜色和指定的宽度和高度填充矩形。
- public abstract void drawOval(int x, int y, int width, int height): 用于绘制具有指定宽度和高度的椭圆。
- public abstract void fillOval(int x, int y, int width, int height): 用于使用默认颜色和指定的宽度和高度填充椭圆。
- public abstract void drawLine(int x1, int y1, int x2, int y2): 用于在点 (x1, y1) 和 (x2, y2) 之间绘制线。
- public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer): 用于绘制指定的图像。
- public abstract void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle): 用于绘制圆形或椭圆弧。
- public abstract void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle): 用于填充圆形或椭圆弧。
- public abstract void setColor(Color c): 用于将图形的当前颜色设置为指定的颜色。
- public abstract void setFont(Font font): 用于将图形的当前字体设置为指定的字体。
|
在 Swing 中显示图形的示例
|