There are number of problems with this code
public class LineEx extends JFrame implements MouseMotionListener,MouseListener{
int x1,y1,x2,y2;
public Line
JFrame).BufferedImage that was loaded.GridBagLayout with no constraint, so it is centered.BorderLayout.CENTER) of a parent component.Note that you might also add the line objects to an expandable collection such as an ArrayList or DefaultListModel, then display them in a JList to the WEST of the image scroll pane. This would make it easier to manage (and potentially delete) groups of lines.