Java full screen background color wont change?

后端 未结 2 1170
醉话见心
醉话见心 2021-01-23 14:01

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

2条回答
  •  自闭症患者
    2021-01-23 14:51

    The painting of the background is done in the paint function. So, you have to invoke super.paint(g) at the start of the paint function.
    Also, you need to override the setBackground function.
    So the code becomes:

    public void paint(Graphics g){
        super.paint(g);
        g.drawString("This is gonna be awesome", 200, 200);
    }
    
    public void setBackground(Color color){
        super.setBackground(color);
        getContentPane().setBackground(color);
    }
    

提交回复
热议问题