Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GUI / EventListener Problem

 
De Huaste
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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


 
Michael Dunn
Ranch Hand
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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)
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Better suitable for the GUI forum. Moving...
 
De Huaste
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic