Why does this JFrame not end up being blue?

Hi
I'm surprised this JFrame didn't work, an I wonder why. It doesn't draw any blue. What might I have done wrong?

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.*;


public class Merrywin extends Thread{
	
	JFrame jFrame;

	public Merrywin() {
		
		
		
		start();
	}
		
		

		
		
		
	

	public void run() {

		System.out.println("Hi");
		jFrame = new JFrame();   
		jFrame.setBounds(10, 0, 1125, 2436);  
		jFrame.setVisible(true);
		
		Graphics G = jFrame.getGraphics();
		G.setColor(Color.BLUE);
		G.fillRect(0, 0, 1000, 2000);
			
				

	}
		
		
	public static void main(String[] args) {
		System.out.println("Maine");

			Merrywin m = new Merrywin();

	}

}

Open in new window

LVL 1
beavoidSelf EmployedAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
It does actually, but so quickly you probably won't see it. It's not the way to do custom painting in Java, since what you paint briefly will be painted away again.
See https://docs.oracle.com/javase/tutorial/uiswing/painting/index.html
girionisCommented:
You need to add a new component, and paint the new component, otherwise you won't be able to see the colour (which, as CEJH mentioned, is being painted once and then repainted over).

Try

public class Merrywin {

	JFrame jFrame;

	public Merrywin() {

		run();
	}

	public void run() {

		System.out.println("Hi");
		jFrame = new JFrame();
		jFrame.setBounds(10, 0, 1125, 2436);
		jFrame.add(new APanel());
		jFrame.setVisible(true);

//		Graphics G = jFrame.getGraphics();
//		G.setColor(Color.BLUE);
//		G.fillRect(0, 0, 1000, 2000);

	}

	public static void main(String[] args) {
		System.out.println("Maine");

		Merrywin m = new Merrywin();

	}

}

class APanel extends JPanel {
	protected void paintComponent(Graphics g) {
        super.paintComponent(g);       
        g.setColor(Color.BLUE);
        g.fillRect(0, 0, 1000, 2000);
    }  
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
beavoidSelf EmployedAuthor Commented:
Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Game Programming

From novice to tech pro — start learning today.