setBackground not working

Hi all. I am just learning Java, and i am trying to go some graphics, but the background color is not showing up, regardless of the color i try. Please see my attached code and let me know any ideas as to why the pictures shows no bacground color.



  • I think u can't use setBackground(Color c) method while working with Graphics. U can only Use setColor(Color c) method.Coz setBackground(Color c) is a swings method.
  • This post has been deleted.
  • You need to use setColor method. I would just fill in the background with the fill rectangle method(just set the coordinates to the full scale of your picture, this will fill your image with blue then you can place all of your shapes over top of it.

    public void paint(Graphics g) {
    g.fillRect(int x, int y, int width, int height);
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!