Extremely Simple Paint Program in Java
Your code formatting deviates from the default Java code formatting, just saying.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

Wildcard imports are kinda bad. If you can avoid them, please do so.

public class Panel extends JPanel

I'm sure you can find a more descriptive name for this class, like PaintablePanel or MousePaintablePanel.

// PROPERTIES

Personally, I don't like such &quot;structuring&quot; comments, they do nothing and only clutter up the code and need to be manually moved when refactoring automatically.

private final int DEFAULT_WIDTH  = 800;
private final int DEFAULT_HEIGHT = 800;
private final Color BACK_COLOR   = Color.WHITE;

Personally I also don't like this column based alignment, it puts my brain into some sort of &quot;column reading mode&quot; which makes it hard for me to associate the value with the variable.

private int x1, y1, x2, y2;

You should not declare multiple variables on the same line, it makes it easy to miss the declaration of variables.

private MyMouseHandler handler;

MyMouseHandler is not a very good name.

public void paintComponent(Graphics g)
{
  super.paintComponent(g);
}

This method seems to override a super method, yet misses the @Override annotation. Also, if it does not do anything, why override it?

public void mousePressed( MouseEvent e )
{
...
     SetUpDrawingGraphics();

Why are you doing this on every mouse press?

public class RunPanel

This is another bad name. What does it run? And it is not a panel.

frame.setDefaultCloseOperation(3);

Any reason why you're not using the constants defined in JFrame?


The program works fine, I can draw normal curves at low mouse speed. But again, as I increase the mouse speed the lines/curves start the get jaggy and ugly.

That is how it is.

I have gathered the two classes into one class file and the program stoped the lag. What is causing this?

I see this behavior in both programs. Combining them in the same file has for sure nothing to do with it.