Read the API documentation for the java.awt.Graphics class and Graphics2D class.
public class MyPanel extends JPanel{
...
public void paintComponent(Graphics g){
super.paintComponent(g);
// call drawLine() here
}