I have some code that creates a full screen icon in java and sets the background color to pink and the foreground color to red. However every time i run it, it never changes the
public void paint(Graphics g){
g.drawString("This is gonna be awesome", 200, 200);
}
The painting of the background is done in the paint()
method. Your overrode the method and didn't invoke super.paint(g)
so the background never gets painted.
However, this is NOT the way to do custom painting. You should NOT override the paint() method of a JFrame. If you want to do custom painting then override the paintComponent()
method of a JPanel
and then add the panel to the frame.
Read the section from the Swing tutorial on Custom Painting for more information.
Edit:
Once you add the super.paint(g), child components of the frame will be painted. This means the content pane gets painted and the content pane is painted over the frame so you won't see the background of the frame, so you also need to add:
//setBackground(Color.PINK);
getContentPane().setBackground(Color.PINK);