Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Igor Mechnikov
Ranch Hand
Posts: 100
Chrome Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Justin Fox
Ranch Hand
Posts: 802
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Igor Mechnikov
Ranch Hand
Posts: 100
Chrome Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic