Class SwingRenderer

java.lang.Object
com.example.renderer.bridge.SwingRenderer
All Implemented Interfaces:
Renderer

public class SwingRenderer extends Object implements Renderer
  • Constructor Details

    • SwingRenderer

      public SwingRenderer()
  • Method Details

    • setGraphics

      public void setGraphics(Graphics2D g)
      设置绘图上下文。

      此方法必须在调用任何绘制方法前调用,用于初始化:

      • 绘图颜色设置为蓝色(BLUE)
      • 线条宽度设置为2像素
      Parameters:
      g - Graphics2D绘图上下文对象
      See Also:
    • drawCircle

      public void drawCircle(int x, int y, int radius)
      绘制圆形
      Specified by:
      drawCircle in interface Renderer
      Parameters:
      x - 圆心x坐标
      y - 圆心y坐标
      radius - 半径(必须>0)
      Throws:
      IllegalArgumentException - 如果半径不合法
    • drawRectangle

      public void drawRectangle(int x, int y, int width, int height)
      绘制矩形
      Specified by:
      drawRectangle in interface Renderer
      Parameters:
      x - 左上角x坐标
      y - 左上角y坐标
      width - 矩形宽度(必须>0)
      height - 矩形高度(必须>0)
      Throws:
      IllegalArgumentException - 如果宽度或高度不合法
    • drawEllipse

      public void drawEllipse(int x, int y, int width, int height)
      绘制椭圆
      Specified by:
      drawEllipse in interface Renderer
      Parameters:
      x - 椭圆外接矩形左上角x坐标
      y - 椭圆外接矩形左上角y坐标
      width - 椭圆宽度(必须>0)
      height - 椭圆高度(必须>0)
      Throws:
      IllegalArgumentException - 如果宽度或高度不合法
    • drawTriangle

      public void drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3)
      绘制三角形。

      实现细节:

      • 使用Polygon类创建三角形路径
      • 继承自父类的线条样式设置
      • 如果Graphics2D上下文未设置,则不执行任何操作
      Specified by:
      drawTriangle in interface Renderer
      Parameters:
      x1 - 第一个顶点x坐标
      y1 - 第一个顶点y坐标
      x2 - 第二个顶点x坐标
      y2 - 第二个顶点y坐标
      x3 - 第三个顶点x坐标
      y3 - 第三个顶点y坐标
      See Also: