• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 100
VI Editor Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 802
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
VI Editor Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

reply
    Bookmark Topic Watch Topic
  • New Topic