[英]Jframe Not Setting Background Color
我尝试了很多不同的方法来让我的项目显示背景颜色。 它仍然不会改变颜色。 我知道这只是需要修复的小问题,但我找不到它。 任何帮助表示赞赏。 (我确实在顶部有导入,不确定 Stack 是否显示)-Liam
import java.awt.Color; //importing things that the code needs
import java.awt.Graphics; //importing things that the code needs
import javax.swing.JFrame; //importing things that the code needs
public class bigJavaClass extends JFrame{ //Jframe is the viewer so we can see what we are drawing
private static final long serialVersionUID = 1L;
public static final int WIDTH = 800;
public static final int HEIGHT = 600;
public static final int R = 200;
public static final int G = 200;
public static final int B = 200;
public static void main(String[] args) {
bigJavaClass test = new bigJavaClass();
test.setSize(WIDTH, HEIGHT);
test.setResizable(false);
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
test.setVisible(true);
test.setBackground(new Color (248, 177, 149)); //background color R, G, B
}
public void paint(Graphics g){
boolean a = false; //for the variable a
boolean b = false; //for the variable b
boolean c = false; //for the variable c
boolean d = false; //for the variable d
class 名称不应以小写字符开头。
不要覆盖 JFrame 上的 paint()。您已经失去了默认的绘制行为,即绘制添加到框架的背景和组件。
“内容窗格”绘制在框架的顶部。 因此,您需要更改内容窗格的背景。 有关框架结构的更多信息,请参阅: 使用顶级容器。 从教程中下载工作示例并进行自定义以了解如何更好地构建代码。
在使框架可见之前设置背景。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.