Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Button and Radio Buttons not working!!!

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Button and Radio Buttons not working!!!

    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);



    }
    }


  2. #2
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: Button and Radio Buttons not working!!!

    i dont see actionlisteners on your buttons and can you post your actionPerformed method?

  3. #3
    Junior Member
    Join Date
    Jul 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Button and Radio Buttons not working!!!

    import java.awt.BorderLayout;
    import java.awt.EventQueue;

    import javax.swing.ButtonGroup;
    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 textLabel;
    private JButton red;
    private JButton orange;
    private JButton yellow;
    private JButton green;
    private JButton blue;
    private JButton cyan;
    private ButtonGroup radioButtonGroup;
    private JPanel panel;
    private JPanel RadioButtonListener;

    /**
    * 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");

    textLabel = 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());

    red.addActionListener(new ButtonListener());
    orange.addActionListener(new ButtonListener());
    yellow.addActionListener(new ButtonListener());

    private class ButtonListener implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource() == red)
    {
    CenterPanel.setBackground(Color.RED);
    }
    else if(e.getSource() == orange)
    {
    CenterPanel.setBackground(Color.ORANGE);
    }
    else if(e.getSource() == yellow)
    {
    CenterPanel.setBackground(Color.YELLOW);
    }
    }
    }

    private class RadioButtonListener implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource()==green)
    {
    messageLabel.setForeground(Color.GREEN);
    }
    else if (e.getSource()==blue)
    {
    messageLabel.setForeground(Color.BLUE);
    }
    else if (e.getSource()==cyan)
    {
    messageLabel.setForeground(Color.CYAN);
    }
    }
    }


    JLabel lblNewLabel = new JLabel("Top buttons change the panel color and bottom buttons change text color");

    private class ButtonListener implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource() == red)
    {
    panel.setBackground(Color.RED);
    }
    else if(e.getSource() == orange)
    {
    panel.setBackground(Color.ORANGE);
    }
    else if(e.getSource() == yellow)
    {
    panel.setBackground(Color.YELLOW);
    }
    }
    }

    private class RadioButtonListener implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource()==green)
    {
    textLabel.setForeground(Color.GREEN);
    }
    else if (e.getSource()==blue)
    {
    textLabel.setForeground(Color.BLUE);
    }
    else if (e.getSource()==cyan)
    {
    textLabel.setForeground(Color.CYAN);
    }
    }
    }



    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)
    .addComponent(rdbtnNewRadioButton)
    .addComponent(btnNewButton))
    .addGap(65)
    .addGroup(groupLayout.createParallelGroup(Alignmen t.LEADING)
    .addGroup(groupLayout.createSequentialGroup()
    .addComponent(btnNewButton_1)
    .addPreferredGap(ComponentPlacement.RELATED, 96, Short.MAX_VALUE)
    .addComponent(btnNewButton_2)
    .addGap(32))
    .addGroup(groupLayout.createSequentialGroup()
    .addGap(22)
    .addComponent(rdbtnNewRadioButton_1)
    .addPreferredGap(ComponentPlacement.RELATED, 69, Short.MAX_VALUE)
    .addComponent(rdbtnNewRadioButton_2)
    .addGap(73)))
    .addContainerGap(20, Short.MAX_VALUE))
    .addGroup(groupLayout.createSequentialGroup()
    .addGap(122)
    .addComponent(panel, GroupLayout.PREFERRED_SIZE, 155, GroupLayout.PREFERRED_SIZE)
    .addContainerGap(157, Short.MAX_VALUE))
    .addGroup(groupLayout.createSequentialGroup()
    .addContainerGap()
    .addComponent(lblNewLabel)
    .addContainerGap(69, 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);



    }
    }

    Thanks!

    --- Update ---

    I've got the design part of it working but its the logic that's killing me

  4. #4
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: Button and Radio Buttons not working!!!

    are you getting any errors when you compile it or run it?

  5. #5
    Junior Member
    Join Date
    Jul 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Button and Radio Buttons not working!!!

    here is an updated code format and still no dice

    import java.awt.Color;
    import java.awt.EventQueue;

    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.plaf.basic.BasicButtonListener;

    import java.awt.BorderLayout;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

    import com.jgoodies.forms.layout.FormLayout;
    import com.jgoodies.forms.layout.ColumnSpec;
    import com.jgoodies.forms.layout.RowSpec;
    import javax.swing.GroupLayout;
    import javax.swing.GroupLayout.Alignment;
    import javax.swing.LayoutStyle.ComponentPlacement;
    import javax.swing.JRadioButton;
    import javax.swing.JLabel;


    public class ColorFactory extends JFrame {

    private final int height=300;
    private final int width=500;
    private JPanel Top;
    private JPanel Middle;
    private JPanel Bottom;
    private JButton red;
    private JButton orange;
    private JButton yellow;
    private JRadioButton green;
    private JRadioButton blue;
    private JRadioButton cyan;
    private JLabel textLabel;
    /**
    * 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");
    setBounds(100, 100, width, height);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


    JButton button = new JButton("red");
    button.setBackground(Color.RED);
    red.addActionListener((java.awt.event.ActionListen er) red);


    JButton btnNewButton = new JButton("yellow");
    btnNewButton.setBackground(Color.YELLOW);
    yellow.addActionListener((java.awt.event.ActionLis tener) yellow);


    JButton btnNewButton_1 = new JButton("orange");
    btnNewButton_1.setBackground(Color.ORANGE);
    orange.addActionListener((java.awt.event.ActionLis tener) orange);

    JRadioButton rdbtnGreen = new JRadioButton("green");
    rdbtnGreen.setForeground(Color.GREEN);
    green.addActionListener((java.awt.event.ActionList ener) rdbtnGreen);

    JRadioButton rdbtnBlue = new JRadioButton("blue");
    rdbtnBlue.setForeground(Color.BLUE);
    blue.addActionListener((java.awt.event.ActionListe ner) rdbtnBlue);

    JRadioButton rdbtnCyan = new JRadioButton("cyan");
    rdbtnCyan.setForeground(Color.CYAN);
    cyan.addActionListener((java.awt.event.ActionListe ner) rdbtnCyan);

    JLabel textLabel = new JLabel("Top Buttons Change the Panel Color and bottom radio buttons change the text color");

    JPanel panel = new JPanel();
    panel.setBackground(Color.WHITE);


    GroupLayout groupLayout = new GroupLayout(getContentPane());
    groupLayout.setHorizontalGroup(
    groupLayout.createParallelGroup(Alignment.TRAILING )
    .addGroup(groupLayout.createSequentialGroup()
    .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .addGroup(groupLayout.createParallelGroup(Alignmen t.LEADING)
    .addGroup(groupLayout.createSequentialGroup()
    .addGroup(groupLayout.createParallelGroup(Alignmen t.TRAILING)
    .addComponent(rdbtnGreen)
    .addComponent(button))
    .addGap(110)
    .addGroup(groupLayout.createParallelGroup(Alignmen t.TRAILING)
    .addComponent(btnNewButton)
    .addComponent(rdbtnBlue)
    .addComponent(panel, GroupLayout.PREFERRED_SIZE, 59, GroupLayout.PREFERRED_SIZE))
    .addGap(137)
    .addGroup(groupLayout.createParallelGroup(Alignmen t.TRAILING)
    .addComponent(btnNewButton_1)
    .addComponent(rdbtnCyan)))
    .addComponent(textLabel))
    .addGap(87))
    );
    groupLayout.setVerticalGroup(
    groupLayout.createParallelGroup(Alignment.LEADING)
    .addGroup(groupLayout.createSequentialGroup()
    .addGap(21)
    .addGroup(groupLayout.createParallelGroup(Alignmen t.BASELINE)
    .addComponent(button)
    .addComponent(btnNewButton)
    .addComponent(btnNewButton_1))
    .addGap(45)
    .addComponent(panel, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)
    .addGap(18)
    .addComponent(textLabel)
    .addPreferredGap(ComponentPlacement.RELATED, 75, Short.MAX_VALUE)
    .addGroup(groupLayout.createParallelGroup(Alignmen t.BASELINE)
    .addComponent(rdbtnGreen)
    .addComponent(rdbtnCyan)
    .addComponent(rdbtnBlue))
    .addGap(26))
    );
    getContentPane().setLayout(groupLayout);





    }
    private class ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource()==green)
    {
    textLabel.setForeground(Color.GREEN);
    }
    else if (e.getSource()==blue)
    {
    textLabel.setForeground(Color.BLUE);
    }
    else if (e.getSource()==cyan)
    {
    textLabel.setForeground(Color.CYAN);
    }
    }
    }
    private class ActionListener1
    {
    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource() == red)
    {
    Middle.setBackground(Color.RED);
    }
    else if(e.getSource() == orange)
    {
    Middle.setBackground(Color.ORANGE);
    }
    else if(e.getSource() == yellow)
    {
    Middle.setBackground(Color.YELLOW);
    }
    }
    }
    }

    --- Update ---

    here is an updated code format and still no dice

    import java.awt.Color;
    import java.awt.EventQueue;

    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.plaf.basic.BasicButtonListener;

    import java.awt.BorderLayout;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

    import com.jgoodies.forms.layout.FormLayout;
    import com.jgoodies.forms.layout.ColumnSpec;
    import com.jgoodies.forms.layout.RowSpec;
    import javax.swing.GroupLayout;
    import javax.swing.GroupLayout.Alignment;
    import javax.swing.LayoutStyle.ComponentPlacement;
    import javax.swing.JRadioButton;
    import javax.swing.JLabel;


    public class ColorFactory extends JFrame {

    private final int height=300;
    private final int width=500;
    private JPanel Top;
    private JPanel Middle;
    private JPanel Bottom;
    private JButton red;
    private JButton orange;
    private JButton yellow;
    private JRadioButton green;
    private JRadioButton blue;
    private JRadioButton cyan;
    private JLabel textLabel;
    /**
    * 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");
    setBounds(100, 100, width, height);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


    JButton button = new JButton("red");
    button.setBackground(Color.RED);
    red.addActionListener((java.awt.event.ActionListen er) red);


    JButton btnNewButton = new JButton("yellow");
    btnNewButton.setBackground(Color.YELLOW);
    yellow.addActionListener((java.awt.event.ActionLis tener) yellow);


    JButton btnNewButton_1 = new JButton("orange");
    btnNewButton_1.setBackground(Color.ORANGE);
    orange.addActionListener((java.awt.event.ActionLis tener) orange);

    JRadioButton rdbtnGreen = new JRadioButton("green");
    rdbtnGreen.setForeground(Color.GREEN);
    green.addActionListener((java.awt.event.ActionList ener) rdbtnGreen);

    JRadioButton rdbtnBlue = new JRadioButton("blue");
    rdbtnBlue.setForeground(Color.BLUE);
    blue.addActionListener((java.awt.event.ActionListe ner) rdbtnBlue);

    JRadioButton rdbtnCyan = new JRadioButton("cyan");
    rdbtnCyan.setForeground(Color.CYAN);
    cyan.addActionListener((java.awt.event.ActionListe ner) rdbtnCyan);

    JLabel textLabel = new JLabel("Top Buttons Change the Panel Color and bottom radio buttons change the text color");

    JPanel panel = new JPanel();
    panel.setBackground(Color.WHITE);


    GroupLayout groupLayout = new GroupLayout(getContentPane());
    groupLayout.setHorizontalGroup(
    groupLayout.createParallelGroup(Alignment.TRAILING )
    .addGroup(groupLayout.createSequentialGroup()
    .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .addGroup(groupLayout.createParallelGroup(Alignmen t.LEADING)
    .addGroup(groupLayout.createSequentialGroup()
    .addGroup(groupLayout.createParallelGroup(Alignmen t.TRAILING)
    .addComponent(rdbtnGreen)
    .addComponent(button))
    .addGap(110)
    .addGroup(groupLayout.createParallelGroup(Alignmen t.TRAILING)
    .addComponent(btnNewButton)
    .addComponent(rdbtnBlue)
    .addComponent(panel, GroupLayout.PREFERRED_SIZE, 59, GroupLayout.PREFERRED_SIZE))
    .addGap(137)
    .addGroup(groupLayout.createParallelGroup(Alignmen t.TRAILING)
    .addComponent(btnNewButton_1)
    .addComponent(rdbtnCyan)))
    .addComponent(textLabel))
    .addGap(87))
    );
    groupLayout.setVerticalGroup(
    groupLayout.createParallelGroup(Alignment.LEADING)
    .addGroup(groupLayout.createSequentialGroup()
    .addGap(21)
    .addGroup(groupLayout.createParallelGroup(Alignmen t.BASELINE)
    .addComponent(button)
    .addComponent(btnNewButton)
    .addComponent(btnNewButton_1))
    .addGap(45)
    .addComponent(panel, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)
    .addGap(18)
    .addComponent(textLabel)
    .addPreferredGap(ComponentPlacement.RELATED, 75, Short.MAX_VALUE)
    .addGroup(groupLayout.createParallelGroup(Alignmen t.BASELINE)
    .addComponent(rdbtnGreen)
    .addComponent(rdbtnCyan)
    .addComponent(rdbtnBlue))
    .addGap(26))
    );
    getContentPane().setLayout(groupLayout);





    }
    private class ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource()==green)
    {
    textLabel.setForeground(Color.GREEN);
    }
    else if (e.getSource()==blue)
    {
    textLabel.setForeground(Color.BLUE);
    }
    else if (e.getSource()==cyan)
    {
    textLabel.setForeground(Color.CYAN);
    }
    }
    }
    private class ActionListener1
    {
    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource() == red)
    {
    Middle.setBackground(Color.RED);
    }
    else if(e.getSource() == orange)
    {
    Middle.setBackground(Color.ORANGE);
    }
    else if(e.getSource() == yellow)
    {
    Middle.setBackground(Color.YELLOW);
    }
    }
    }
    }

  6. #6
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: Button and Radio Buttons not working!!!

    first i think you should leave this whole code alone for a bit and work on something a little easier...instead of having 3 buttons and 3 radio

    make a jframe and add the panel and 1 button and see if you can get that to color change and once you can get that do the same with a radio

    then go back to this code with the working code from the small example and put it into this code

    i think you should try this and then if you have questions about how to get 1 to work post the code and ill help you out cause im finding this code too hard to read through lol....also i think a smaller example will let you learn easier how it will work instead of trying to get a bunch of stuff going at the same time

Similar Threads

  1. [SOLVED] set specific location for radio buttons
    By nosxlimit in forum Java Theory & Questions
    Replies: 3
    Last Post: June 18th, 2012, 09:15 AM
  2. [SOLVED] Creating Dynamically Radio Buttons, Labels
    By Onur in forum Java Theory & Questions
    Replies: 15
    Last Post: August 25th, 2011, 09:39 AM
  3. Help with radio buttons and results.
    By Bewitched1 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 3rd, 2011, 04:01 PM
  4. radio buttons stop working
    By tabutcher in forum AWT / Java Swing
    Replies: 2
    Last Post: March 5th, 2010, 09:28 AM
  5. [SOLVED] Using html Radio Buttons with Servlets
    By oss_2008 in forum Java Servlet
    Replies: 2
    Last Post: June 25th, 2009, 06:39 AM