When lines are drawn on the screen, vertical and horizontal lines appear perfectly straight.
However, when they are on a diagonal, especially near vertical or horizontal, "jaggies" appear, giving the line a step-like appearance.
This can be avoided in Java 2's Graphics2D class by requesting that edges are antialiased.
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g; // See note below
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
// Use g2 for all following operations
g2.drawLine(0, 0, 100, 80);
. . .
}
paintComponent method is already a
Graphics2D object.