In Java, I need to draw a simple line with the paintComponent. Here is my attempt, but nothing was shown when I executed the program. Please show me the correct way of doing this.
import javax.swing.*;
import java.awt.*;
public class DrawLine extends JPanel {
public Illusion(Color backColor){
setBackground(backColor);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(Color.black);
g.drawLine(100, 100, 300, 100);
}
}