I am writing a Paint App for a homework and I'm struggling with dragging the mouse.
The MousePressed method works (prints coordinates) but when I drag the mouse, it throws an NullPointerException ("Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException").
package view;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.util.Enumeration;
import javax.management.remote.SubjectDelegationPermission;
import javax.swing.AbstractButton;
import javax.swing.ButtonGroup;
import javax.swing.JColorChooser;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import com.sun.javafx.geom.Rectangle;
import com.sun.prism.shader.DrawEllipse_Color_AlphaTest_Loader;
public class NetpaintGUI extends JFrame {
    // Variables for selecting Color and Shape
    private JPanel selectionArea = new JPanel();
    private ButtonGroup shapeSelectorGroup = new ButtonGroup();
    private JRadioButton ellipseBtn = new JRadioButton("Ellipse");
    private JRadioButton rectangleBtn = new JRadioButton("Rectangle");
    private JRadioButton lineBtn = new JRadioButton("Line");
    private JColorChooser colorChooser = new JColorChooser();
    private Graphics2D draw;
    private Color currColor;
    private int currX, currY, prevX, prevY;
    public static void main(String[] args) {
        JFrame paintFrame = new NetpaintGUI();
        paintFrame.setVisible(true);
    }
    public NetpaintGUI() {
        setUpModel();
        this.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
            }
        });
    }
    public void drawShape(Graphics g) {
        if (ellipseBtn.isSelected()) {
            System.out.println("Ellipse, Bro");
        }
        else if (rectangleBtn.isSelected()) {
            System.out.println("Rectangle, Bro");
        }
        else if (lineBtn.isSelected()) {
            System.out.println("Line, Bro");
        }
    }
    private void setUpModel() {
        // TODO: Read info (persistence)
        // Set JFrame size, color, font, title
        this.setTitle("UA Netpaint");
        this.setSize(1200, 700);
        this.getContentPane().setBackground(Color.WHITE);
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        this.setFont(new Font("Courier", Font.BOLD, 16));
        // Add ColorSelector to Panel
        selectionArea.add(colorChooser);
        // Add RadioButtons to ButtonGroup and to Panel, and add Panel to Frame
        shapeSelectorGroup.add(ellipseBtn);
        shapeSelectorGroup.add(rectangleBtn);
        shapeSelectorGroup.add(lineBtn);
        selectionArea.add(ellipseBtn);
        selectionArea.add(rectangleBtn);
        selectionArea.add(lineBtn);
        ellipseBtn.setSelected(true);
        this.add(selectionArea, BorderLayout.SOUTH);
        addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                prevX = e.getX();
                prevY = e.getY();
                System.out.println("X: " + prevX + "   Y: " + prevY);
            }
        });
        addMouseMotionListener(new MouseMotionAdapter() {
            public void mouseDragged(MouseEvent e) {
                currX = e.getX();
                currY = e.getY();
                draw.setColor(colorChooser.getColor());
                if (ellipseBtn.isSelected()) {
                    draw.drawOval(prevX, prevY, currX-prevX, currY-prevY);
                }
                else if (lineBtn.isSelected()) {
                    draw.drawLine(prevX, prevY, currX, currY);
                }
                else if (rectangleBtn.isSelected()) {
                    draw.drawRect(prevX, prevY, currX-prevX, currY-prevY);
                }
                repaint();
                prevX = currX;
                prevY = currY;
            }
        });
    }
}
This is what I've thrown together. The problematic code segment is the very last method in the class and the exception is thrown when the "draw.draw[Line/Oval/Rect]" line is called.
Please let me know what I'm messing up! Thanks, everyone!
