如何优化绘制这些标记?

时间:2019-01-07 21:15:31

标签: java performance swing drawing

我目前正在研究Java / Swing中的绘图程序。目前,我制作了JPanel,上面带有轴和标记。

我的问题是我该如何合并使用正值标记绘制负数的循环?

目前我做了这样的事情:

 private void DrawAxisMarkers(Graphics g) {

    //X  MARKERS
    g.setColor(Color.red);
    for (int xI = 0; xI <= this.getWidth(); xI += MatherProperties.SCALE) {
        g.drawLine(xI * MatherProperties.SCALE+ origin.x, markerSize + origin.y, xI * MatherProperties.SCALE + origin.x, -markerSize + origin.y);
    }
    for (int xI = 0; xI <= this.getWidth(); xI += MatherProperties.SCALE) {
        g.drawLine(-xI * MatherProperties.SCALE + origin.x, markerSize + origin.y, -xI * MatherProperties.SCALE + origin.x, -markerSize + origin.y);
    }

    //Y MARKERS
    g.setColor(Color.blue);
    for (int yI = 0; yI <= this.getHeight(); yI += MatherProperties.SCALE) {
        g.drawLine(markerSize + origin.x, yI * MatherProperties.SCALE + origin.y, -markerSize + origin.x, yI * MatherProperties.SCALE + origin.y);
    }
    for (int yI = 0; yI <= this.getHeight(); yI += MatherProperties.SCALE) {
        g.drawLine(markerSize + origin.x, -yI * MatherProperties.SCALE + origin.y, -markerSize + origin.x, -yI * MatherProperties.SCALE + origin.y);
    }
}

我对如何合并它们没有任何想法:\而且这些轴的原点在中间,但用户可以更改原点。

图形:

0 个答案:

没有答案