File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Want to pass randomly chosen color to setBackground(Color.xyz) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Want to pass randomly chosen color to setBackground(Color.xyz)" Watch "Want to pass randomly chosen color to setBackground(Color.xyz)" New topic
Author

Want to pass randomly chosen color to setBackground(Color.xyz)

Igor Mechnikov
Ranch Hand

Joined: Feb 13, 2011
Posts: 100

I think the issue is wrong argument type, string v. static.
What is the right way to do this?




1 error found:
File: /home/whoami/javaClass/EventDemo.java [line: 280]
Error: /home/whoami/javaClass/EventDemo.java:280: cannot find symbol
symbol : variable backgroundColor
location: class java.awt.Color

I also tried



And erred:

File: /home/whoami/javaClass/EventDemo.java [line: 281]
Error: /home/whoami/javaClass/EventDemo.java:281: cannot find symbol
symbol : method setBackground(java.lang.String)
location: class EventDemo.DisplayPanel

Both errors are on the last line of the code


String knock = "\u042F \u0418\u0433\u043e\u0440\u044c";
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
Instead of using a String [], use a Color []. That way you can get a random integer and get the Color object at that index and use it.
Color doesn't have a static variable/function called 'backgroundColor', that's why you're getting that error.

Justin


You down with OOP? Yeah you know me!
Igor Mechnikov
Ranch Hand

Joined: Feb 13, 2011
Posts: 100

Justin Fox wrote:Instead of using a String [], use a Color []. That way you can get a random integer and get the Color object at that index and use it.
Color doesn't have a static variable/function called 'backgroundColor', that's why you're getting that error.

Justin[/quote

Great advice. Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Want to pass randomly chosen color to setBackground(Color.xyz)
 
Similar Threads
Compile Errors - Head First - GuessGame
import java.io.*; problem
Beginning GUI programming exercise. Please help to figure out why it does not compile.
problem with parameters
NEED HELP!!!