aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes GUI / EventListener Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GUI / EventListener Problem" Watch "GUI / EventListener Problem" New topic
Author

GUI / EventListener Problem

De Huaste
Greenhorn

Joined: Nov 18, 2012
Posts: 11
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

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: Jul 26, 2007
Posts: 10522
    
    9

Better suitable for the GUI forum. Moving...


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
De Huaste
Greenhorn

Joined: Nov 18, 2012
Posts: 11
Michael. thanks for going over this. Needless to say, your advice worked. Maneesh, thanks for moving to the appropriate forum
 
 
subject: GUI / EventListener Problem