Java Jframe未设置背景色
为了让我的项目显示背景色,我尝试了很多不同的方法。它仍然不会改变颜色。我知道有点小问题需要解决,但我找不到。感谢您的帮助。(我确实在顶部有导入,不确定堆栈是否显示) -利亚姆Java Jframe未设置背景色,java,eclipse,Java,Eclipse,为了让我的项目显示背景色,我尝试了很多不同的方法。它仍然不会改变颜色。我知道有点小问题需要解决,但我找不到。感谢您的帮助。(我确实在顶部有导入,不确定堆栈是否显示) -利亚姆 在使框架可见之前设置背景 类名不应以小写字符开头 不要覆盖JFrame上的paint()。您丢失了默认的绘制行为,即绘制添加到帧中的背景和组件 “内容窗格”绘制在框架顶部。因此,您需要更改内容窗格的背景。有关框架结构的详细信息,请参见。从教程中下载工作示例并进行自定义,以了解如何更好地构造代码 (1-)不需要。当您更
在使框架可见之前设置背景
(1-)不需要。当您更改组件的属性时,Swing组件将重新绘制它们自己。您的意思是说类名不应以小写字符开头吗?@VGR oops。。。这当然是我的意思。固定的。谢谢
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