This is probably a really stupid error but iv’e just started learning the .awt package. I followed a tutorial to the letter, in the video his window’s background is red, there are no errors in my code yet it won’t change the background color.
Thanks for any help!
import java.awt.Color;
import javax.swing.*;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame f = new JFrame();
f.setVisible(true);
f.setSize(350,350);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setTitle("Window");
f.setBackground(Color.RED);
}
}
1)
JFramecan’t do that, you have to changeColorfor content pane e.g.2) You need to wrap GUI related code (in
mainmethod) to theinvokeLaterFor example: