Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

GUI / EventListener Problem

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Gang,

This is my first GUI attempt, unless you count JOptionPane. It's a little assignment for class that compiles fine, but there's something going on with the logic. I need to set the background color of the buttons (to red, orange, yellow respectively) in the button panel and create an action event that changes the messageLabel's text color when that of the corresponding button (green, blue, cyan) is clicked.

To the best of my knowledge, it's all there but the program acts otherwise. Help is appreciated


 
Ranch Hand
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> public class Color extends JFrame

there's already an awt class Color, so expect problems duplicating the class name.

> and create an action event that changes the messageLabel's text color when that of the corresponding button (green, blue, cyan) is clicked.

no, your code changes the foreground of the panel, not the messageLabel
centerPanel.setForeground(Color.GREEN); etc

and it still won't work, as you've declared messageLabel twice
once in buildPanel(), again in the Color() constructor (remove the one in the constructor)
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Better suitable for the GUI forum. Moving...
 
De Huaste
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Michael. thanks for going over this. Needless to say, your advice worked. Maneesh, thanks for moving to the appropriate forum
 
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic