Creating the game window

So… I don’t know why this is a problem for me. But this code doesn’t seem to work right… without the paint method everything works fine, but when I just want to draw text onto the screen, it does, it gets rid of the gray background and somehow “copies” the background that is currently behind the window for some reason.

package javagame;
import java.awt.Graphics;
import javax.swing.JFrame;

public class JavaGame extends JFrame
{
    public JavaGame()
    {
        setTitle("Java Game");
        setSize(500, 400);
        setResizable(false);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    
    public void paint(Graphics g)
    {
        g.drawString("Hello World", 100, 100);
    }
    
    public static void main(String[] args)
    {
        new JavaGame();
    }
}

Below is the game window that is created, with the background instead of being the default grey, it is whatever was behind the window right after compile time.

Why is it doing this? Thanks for the help!