我已经按照无数其他教程的建议来改变JFrame的背景颜色,但我没有运气。这是我的初始化和创建框架的代码
package frameTests;
import javax.swing.*;
import java.awt.*;
@SuppressWarnings("serial")
public class Foo extends JPanel {
public static void frameInit(Foo foobar){
// window initialization
JFrame frame = new JFrame("Spaceship Defenders!");
frame.add(foobar);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setBackground(Color.black);
frame.setSize(500,500);
frame.setVisible(true);
frame.setLocationRelativeTo(null);// center frame in screen.
}
public static void main(String[] args) throws InterruptedException{
Foo bar = new Foo();
frameInit(bar);
}
}