'Way to draw to single pixel, in Jpanel

I am currently working on a 3d engine but have ran in to a very annoying problem with writing my own method to draw a filled polygon. The reason I need this is that I have to determine whether any given pixel should be drawn pixel by pixel due to occlusion. I have read about using Graphics.drawLine(); which the same xy coordinates to produce a dot and using a 1 by 1 or even 0 by 0 square to draw a pixel but these have both had problems for me, drawing using a line method, like this:

for (int x = min_x; x < max_x; x++) {
    for (int y = min_y; y < max_y; y++) {
        if (inp.contains(x, y)){
            g.drawLine(x, y, x, y);
                    
            }
        }
    }
}

using a brute force method produces a bunch of dots and not a filled shape image example of dots

and the other using squares produces jagged edges: example of jagged shape Any help is greatly appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source