I cant seem to get the text to change color from radio button selection and the panel to change color upon button click!
heres my code
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.FlowLayout;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import javax.swing.JRadioButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ColorFactory extends JFrame {
private JPanel contentPane;
private final int WINDOW_WIDTH = 500;
private final int WINDOW_HEIGHT = 300;
private JLabel text;
private JButton red;
private JButton orange;
private JButton yellow;
private JButton green;
private JButton blue;
private JButton cyan;
private JButton ButtonListener;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ColorFactory frame = new ColorFactory();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public ColorFactory() {
super ("Color Factory");
text = new JLabel ("Top buttons change the panel color and bottom buttons change text color");
setSize (WINDOW_WIDTH, WINDOW_HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
JButton btnNewButton = new JButton("red");
btnNewButton.setBackground(Color.RED);
btnNewButton.setForeground(Color.BLACK);
JRadioButton rdbtnNewRadioButton = new JRadioButton("green");
rdbtnNewRadioButton.setForeground(Color.GREEN);
JButton btnNewButton_1 = new JButton("yellow");
btnNewButton_1.setBackground(Color.YELLOW);
btnNewButton_1.setForeground(Color.BLACK);
JRadioButton rdbtnNewRadioButton_1 = new JRadioButton("blue");
rdbtnNewRadioButton_1.setForeground(Color.BLUE);
JRadioButton rdbtnNewRadioButton_2 = new JRadioButton("cyan");
rdbtnNewRadioButton_2.setForeground(Color.CYAN);
JButton btnNewButton_2 = new JButton("orange");
btnNewButton_2.setBackground(Color.ORANGE);
btnNewButton_2.setForeground(Color.BLACK);
green.addActionListener(new RadioButtonListener());
blue.addActionListener(new RadioButtonListener());
cyan.addActionListener(new RadioButtonListener());
JLabel lblNewLabel = new JLabel("Top buttons change the panel color and bottom buttons change text color");
JPanel panel = new JPanel();
panel.setBackground(Color.WHITE);
panel.setForeground(Color.WHITE);
GroupLayout groupLayout = new GroupLayout(getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(38)
.addGroup(groupLayout.createParallelGroup(Alignmen t.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(lblNewLabel)
.addContainerGap())
.addGroup(groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(Alignmen t.LEADING)
.addComponent(rdbtnNewRadioButton)
.addComponent(btnNewButton))
.addGap(65)
.addGroup(groupLayout.createParallelGroup(Alignmen t.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(btnNewButton_1)
.addPreferredGap(ComponentPlacement.RELATED, 98, Short.MAX_VALUE)
.addComponent(btnNewButton_2)
.addGap(32))
.addGroup(groupLayout.createSequentialGroup()
.addGap(22)
.addComponent(rdbtnNewRadioButton_1)
.addPreferredGap(ComponentPlacement.RELATED, 82, Short.MAX_VALUE)
.addComponent(rdbtnNewRadioButton_2)
.addGap(73)))
.addContainerGap(33, Short.MAX_VALUE))))
.addGroup(groupLayout.createSequentialGroup()
.addGap(122)
.addComponent(panel, GroupLayout.PREFERRED_SIZE, 155, GroupLayout.PREFERRED_SIZE)
.addContainerGap(157, Short.MAX_VALUE))
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(26)
.addGroup(groupLayout.createParallelGroup(Alignmen t.BASELINE)
.addComponent(btnNewButton)
.addComponent(btnNewButton_1)
.addComponent(btnNewButton_2))
.addGap(51)
.addComponent(lblNewLabel)
.addGap(18)
.addComponent(panel, GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE)
.addGap(30)
.addGroup(groupLayout.createParallelGroup(Alignmen t.BASELINE)
.addComponent(rdbtnNewRadioButton)
.addComponent(rdbtnNewRadioButton_2)
.addComponent(rdbtnNewRadioButton_1))
.addGap(27))
);
panel.setLayout(new BorderLayout(0, 0));
getContentPane().setLayout(groupLayout);
}
}