Howdy, Stranger!

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

Categories

setBackground not working

teahouteahou Member Posts: 2
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.

thanks.

Comments

  • krishbalodakrishbaloda Member Posts: 45
    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.
  • krishbalodakrishbaloda Member Posts: 45
    This post has been deleted.
  • MiggityMikeMiggityMike Member Posts: 17
    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.setColor(Color.BLUE);
    g.fillRect(int x, int y, int width, int height);
    }
Sign In or Register to comment.