如何在Java中绘制二维图形?

如何在Java中绘制二维图形?,java,graphics,2d,java-2d,Java,Graphics,2d,Java 2d,我有两个不同的清单。它们中的每一个都包含x和y值对(它们既有正值也有负值)。如何在二维轴上绘制它们?我想为每个值设置点,第一个列表为蓝色,第二个列表为红色 我的列表类型: List<List<Double>> List<Double> inside of List<...> has 2 variables, first of it for x value and the second one is for y value. 列表 列表中的列表有

我有两个不同的清单。它们中的每一个都包含x和y值对(它们既有正值也有负值)。如何在二维轴上绘制它们?我想为每个值设置
点,第一个列表为蓝色,第二个列表为红色

我的列表类型:

List<List<Double>>

List<Double> inside of List<...> has 2 variables, first of it for x value and the second one is for y value.
列表
列表中的列表有两个变量,第一个变量表示x值,第二个变量表示y值。
然而,我只需要知道如何在Java(桌面应用程序)上绘制二维图形,并将点放在任何我想要的地方,改进变量的代码就不那么重要了

PS:

我希望那种图形的
越来越简单

比如:


假设将Swing与面板一起使用,则可以使用以下选项:

public class JImagePanelExample extends JPanel {

    private BufferedImage image;
    private Graphics2D drawingBoard;
    private int x, y; // Image position in the panel

    // Let's assume image is a chart and you need to draw lines
    public JImagePanelExample(BufferedImage image, int x, int y) {

        super();
        this.image = image;

        // Retrieving a mean to draw lines
        drawingBoard = image.createGraphics();

        // Draw what you need to draw (see other methods too)
        drawingBoard.drawLine(0, 10, 35, 55);

    }

    // Called by Swing to draw the image in the panel
    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(image, x, y, null);
    }

}

如果您不想使用Swing,只需要在2D中绘制,请只关注
BuffereImage
Graphics2D

有一个Java 2D API:通过web搜索可以很容易地找到许多图表库。

您可以使用类似()的库。web上有很多示例,使用起来非常简单

下面是一个与您的要求相匹配的示例: