所以我在 java 中有一个蛇程序,运行良好,但是在我的 Frame 类中我无法更改我JFrame
的内容窗格的背景颜色,我使用getContentPane().setBackground(Color.DARK_GRAY);
但它不起作用,有什么帮助吗?
这是我的Frame
课:
package mainpackage;
import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.JFrame;
public class Frame extends JFrame {
private static final long serialVersionUID = 1L;
public Frame() {
getContentPane().setBackground(Color.BLACK); \\NOT WORKING !!
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("Snake by Sarp~");
setResizable(false);
init();
}
public void init() {
setLayout(new GridLayout(1, 1, 0, 0));
Screen s = new Screen();
add(s);
pack();
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] args) {
new Frame();
}
}