0

I am trying to create an object of the class Color in awt to add it to the background of my JFrame ..but JCreator keep giving me this error message : .java:23: error: cannot find symbol getContentPane().setBackground(Color.color); ^ symbol: variable color location: class Color 1 error


even when I am importing the Color class ... here is part of my code:

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.ImageIcon;
import java.awt.event.*;
import javax.swing.BorderFactory;
import java.awt.Font;
import java.awt.Color;
public class myframe extends JFrame implements ActionListener 
{       

    public myframe()
     {
        setLayout(null);
        Color color = new Color(135,206,235);
       // Color skyblue = new Color((float)135,(float)206,(float)235);
        getContentPane().setBackground(Color.color);
        ImageIcon icon = new ImageIcon("horizntal logo.gif");
        setIconImage(icon.getImage());
Amani
  • 39
  • 6
  • Replace `setBackground(Color.color)` with `setBackground(color)` . – Arnaud Dec 07 '16 at 08:44
  • thank you !!but I would like to know what's the reason – Amani Dec 07 '16 at 08:47
  • `Color.color` would be a static `color` field inside the `Color`class, and such field doesn't exist. What you want is simply to pass your `color` variable, you don't have to prefix it with a class name or anything . – Arnaud Dec 07 '16 at 08:50
  • 1) Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). 2) Please learn common Java nomenclature (naming conventions - e.g. `EachWordUpperCaseClass`, `firstWordLowerCaseMethod()`, `firstWordLowerCaseAttribute` unless it is an `UPPER_CASE_CONSTANT`) and use it consistently. – Andrew Thompson Dec 07 '16 at 20:41

0 Answers0